mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-12 20:29:23 +02:00
* fixed setstring for unicode/widestring: don't stop at embedded #0
characters, don't expect that buffer is null-terminated (mantis #14740) git-svn-id: trunk@13826 -
This commit is contained in:
parent
00049897b3
commit
6a0755e897
1
.gitattributes
vendored
1
.gitattributes
vendored
@ -9318,6 +9318,7 @@ tests/webtbs/tw14536.pp svneol=native#text/plain
|
|||||||
tests/webtbs/tw14553.pp svneol=native#text/pascal
|
tests/webtbs/tw14553.pp svneol=native#text/pascal
|
||||||
tests/webtbs/tw1470.pp svneol=native#text/plain
|
tests/webtbs/tw1470.pp svneol=native#text/plain
|
||||||
tests/webtbs/tw1472.pp svneol=native#text/plain
|
tests/webtbs/tw1472.pp svneol=native#text/plain
|
||||||
|
tests/webtbs/tw14740.pp svneol=native#text/plain
|
||||||
tests/webtbs/tw1477.pp svneol=native#text/plain
|
tests/webtbs/tw1477.pp svneol=native#text/plain
|
||||||
tests/webtbs/tw1479.pp svneol=native#text/plain
|
tests/webtbs/tw1479.pp svneol=native#text/plain
|
||||||
tests/webtbs/tw1485.pp svneol=native#text/plain
|
tests/webtbs/tw1485.pp svneol=native#text/plain
|
||||||
|
@ -1647,18 +1647,10 @@ end;
|
|||||||
|
|
||||||
|
|
||||||
Procedure SetString (Out S : UnicodeString; Buf : PUnicodeChar; Len : SizeInt);
|
Procedure SetString (Out S : UnicodeString; Buf : PUnicodeChar; Len : SizeInt);
|
||||||
var
|
|
||||||
BufLen: SizeInt;
|
|
||||||
begin
|
begin
|
||||||
SetLength(S,Len);
|
SetLength(S,Len);
|
||||||
If (Buf<>Nil) and (Len>0) then
|
If (Buf<>Nil) and (Len>0) then
|
||||||
begin
|
Move (Buf[0],S[1],Len*sizeof(UnicodeChar));
|
||||||
BufLen := IndexWord(Buf^, Len+1, 0);
|
|
||||||
If (BufLen>0) and (BufLen < Len) then
|
|
||||||
Len := BufLen;
|
|
||||||
Move (Buf[0],S[1],Len*sizeof(UnicodeChar));
|
|
||||||
PUnicodeChar(Pointer(S)+Len*sizeof(UnicodeChar))^:=#0;
|
|
||||||
end;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
@ -1017,18 +1017,10 @@ end;
|
|||||||
|
|
||||||
|
|
||||||
Procedure SetString (Out S : WideString; Buf : PWideChar; Len : SizeInt);
|
Procedure SetString (Out S : WideString; Buf : PWideChar; Len : SizeInt);
|
||||||
var
|
|
||||||
BufLen: SizeInt;
|
|
||||||
begin
|
begin
|
||||||
SetLength(S,Len);
|
SetLength(S,Len);
|
||||||
If (Buf<>Nil) and (Len>0) then
|
If (Buf<>Nil) and (Len>0) then
|
||||||
begin
|
Move (Buf[0],S[1],Len*sizeof(WideChar));
|
||||||
BufLen := IndexWord(Buf^, Len+1, 0);
|
|
||||||
If (BufLen>0) and (BufLen < Len) then
|
|
||||||
Len := BufLen;
|
|
||||||
Move (Buf[0],S[1],Len*sizeof(WideChar));
|
|
||||||
PWideChar(Pointer(S)+Len*sizeof(WideChar))^:=#0;
|
|
||||||
end;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
@ -1434,18 +1434,10 @@ end;
|
|||||||
|
|
||||||
|
|
||||||
Procedure SetString (Out S : WideString; Buf : PWideChar; Len : SizeInt);
|
Procedure SetString (Out S : WideString; Buf : PWideChar; Len : SizeInt);
|
||||||
var
|
|
||||||
BufLen: SizeInt;
|
|
||||||
begin
|
begin
|
||||||
SetLength(S,Len);
|
SetLength(S,Len);
|
||||||
If (Buf<>Nil) and (Len>0) then
|
If (Buf<>Nil) and (Len>0) then
|
||||||
begin
|
Move (Buf[0],S[1],Len*sizeof(WideChar));
|
||||||
BufLen := IndexWord(Buf^, Len+1, 0);
|
|
||||||
If (BufLen>0) and (BufLen < Len) then
|
|
||||||
Len := BufLen;
|
|
||||||
Move (Buf[0],S[1],Len*sizeof(WideChar));
|
|
||||||
PWideChar(Pointer(S)+Len*sizeof(WideChar))^:=#0;
|
|
||||||
end;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
16
tests/webtbs/tw14740.pp
Normal file
16
tests/webtbs/tw14740.pp
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
var
|
||||||
|
w: widestring;
|
||||||
|
u: unicodestring;
|
||||||
|
pw: pwidechar;
|
||||||
|
pu: punicodechar;
|
||||||
|
begin
|
||||||
|
pw:='abc'#0'def';
|
||||||
|
setstring(w,pw,7);
|
||||||
|
if w<>'abc'#0'def' then
|
||||||
|
halt(1);
|
||||||
|
|
||||||
|
pu:='abc'#0'def';
|
||||||
|
setstring(u,pu,7);
|
||||||
|
if u<>'abc'#0'def' then
|
||||||
|
halt(2);
|
||||||
|
end.
|
Loading…
Reference in New Issue
Block a user