mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-10-15 13:26:03 +02:00
* fixed null-termination in StringToWideChar() if the buffer is larger than
the string (mantis #22669) git-svn-id: trunk@22124 -
This commit is contained in:
parent
b353a2ff27
commit
504544e173
1
.gitattributes
vendored
1
.gitattributes
vendored
@ -12783,6 +12783,7 @@ tests/webtbs/tw22593.pp svneol=native#text/plain
|
||||
tests/webtbs/tw2260.pp svneol=native#text/plain
|
||||
tests/webtbs/tw22613.pp svneol=native#text/plain
|
||||
tests/webtbs/tw2266.pp svneol=native#text/plain
|
||||
tests/webtbs/tw22669.pp svneol=native#text/plain
|
||||
tests/webtbs/tw2267.pp svneol=native#text/plain
|
||||
tests/webtbs/tw2268.pp svneol=native#text/plain
|
||||
tests/webtbs/tw2269.pp svneol=native#text/plain
|
||||
|
@ -1030,16 +1030,15 @@ function WideCharToString(S : PWideChar) : UnicodeString;
|
||||
{$define FPC_HAS_STRING_LEN_TO_WIDECHAR}
|
||||
function StringToWideChar(const Src : RawByteString;Dest : PWideChar;DestSize : SizeInt) : PWideChar;
|
||||
var
|
||||
temp:widestring;
|
||||
temp: widestring;
|
||||
Len: SizeInt;
|
||||
begin
|
||||
widestringmanager.Ansi2WideMoveProc(PChar(Src),StringCodePage(Src),temp,Length(Src));
|
||||
if Length(temp)<DestSize then
|
||||
move(temp[1],Dest^,Length(temp)*SizeOf(WideChar))
|
||||
else
|
||||
move(temp[1],Dest^,(DestSize-1)*SizeOf(WideChar));
|
||||
|
||||
Dest[DestSize-1]:=#0;
|
||||
|
||||
Len:=Length(temp);
|
||||
if DestSize<=Len then
|
||||
Len:=Destsize-1;
|
||||
move(temp[1],Dest^,Len*SizeOf(WideChar));
|
||||
Dest[Len]:=#0;
|
||||
result:=Dest;
|
||||
end;
|
||||
{$endif FPC_HAS_STRING_LEN_TO_WIDECHAR}
|
||||
|
@ -592,14 +592,15 @@ end;
|
||||
{$define FPC_HAS_STRING_LEN_TO_WIDECHAR}
|
||||
function StringToWideChar(const Src : RawByteString;Dest : PWideChar;DestSize : SizeInt) : PWideChar;
|
||||
var
|
||||
temp:widestring;
|
||||
temp: widestring;
|
||||
Len: SizeInt;
|
||||
begin
|
||||
temp:=src;
|
||||
if Length(temp)<DestSize then
|
||||
JLString(temp).getChars(0,length(temp),TJCharArray(Dest),0)
|
||||
else
|
||||
JLString(temp).getChars(0,DestSize-1,TJCharArray(Dest),0);
|
||||
Dest[DestSize-1]:=#0;
|
||||
Len:=Length(temp);
|
||||
if DestSize<=Len then
|
||||
Len:=Destsize-1;
|
||||
JLString(temp).getChars(0,Len,TJCharArray(Dest),0);
|
||||
Dest[Len]:=#0;
|
||||
result:=Dest;
|
||||
end;
|
||||
|
||||
|
24
tests/webtbs/tw22669.pp
Normal file
24
tests/webtbs/tw22669.pp
Normal file
@ -0,0 +1,24 @@
|
||||
program tw22669;
|
||||
|
||||
{$ifdef fpc}
|
||||
{$mode objfpc}{$H+}
|
||||
{$else}
|
||||
{$APPTYPE CONSOLE}
|
||||
{$endif}
|
||||
|
||||
var buf:array[1..11] of widechar;
|
||||
s:ansistring;
|
||||
begin
|
||||
buf:='isnotempty';
|
||||
s:='test';
|
||||
StringToWideChar(s,@buf[1],10);
|
||||
s:=widestring(pwidechar(@buf[1]));
|
||||
if s<>'test' then
|
||||
halt(1);
|
||||
s:='0123456789';
|
||||
StringToWideChar(s,@buf[1],10);
|
||||
s:=widestring(pwidechar(@buf[1]));
|
||||
if s<>'012345678' then
|
||||
halt(2);
|
||||
end.
|
||||
|
Loading…
Reference in New Issue
Block a user