From 6a0755e897af6c84a343426896478b31caa5492d Mon Sep 17 00:00:00 2001 From: Jonas Maebe Date: Fri, 9 Oct 2009 16:12:03 +0000 Subject: [PATCH] * 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 - --- .gitattributes | 1 + rtl/inc/ustrings.inc | 10 +--------- rtl/inc/wstrings.inc | 10 +--------- rtl/inc/wustring22.inc | 10 +--------- tests/webtbs/tw14740.pp | 16 ++++++++++++++++ 5 files changed, 20 insertions(+), 27 deletions(-) create mode 100644 tests/webtbs/tw14740.pp diff --git a/.gitattributes b/.gitattributes index 169ac28328..afc2824917 100644 --- a/.gitattributes +++ b/.gitattributes @@ -9318,6 +9318,7 @@ tests/webtbs/tw14536.pp svneol=native#text/plain tests/webtbs/tw14553.pp svneol=native#text/pascal tests/webtbs/tw1470.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/tw1479.pp svneol=native#text/plain tests/webtbs/tw1485.pp svneol=native#text/plain diff --git a/rtl/inc/ustrings.inc b/rtl/inc/ustrings.inc index 0838f68f0c..27d55ded7c 100644 --- a/rtl/inc/ustrings.inc +++ b/rtl/inc/ustrings.inc @@ -1647,18 +1647,10 @@ end; Procedure SetString (Out S : UnicodeString; Buf : PUnicodeChar; Len : SizeInt); -var - BufLen: SizeInt; begin SetLength(S,Len); If (Buf<>Nil) and (Len>0) then - begin - 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; + Move (Buf[0],S[1],Len*sizeof(UnicodeChar)); end; diff --git a/rtl/inc/wstrings.inc b/rtl/inc/wstrings.inc index 89b85a5dc9..348645ee1f 100644 --- a/rtl/inc/wstrings.inc +++ b/rtl/inc/wstrings.inc @@ -1017,18 +1017,10 @@ end; Procedure SetString (Out S : WideString; Buf : PWideChar; Len : SizeInt); -var - BufLen: SizeInt; begin SetLength(S,Len); If (Buf<>Nil) and (Len>0) then - begin - 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; + Move (Buf[0],S[1],Len*sizeof(WideChar)); end; diff --git a/rtl/inc/wustring22.inc b/rtl/inc/wustring22.inc index 3f79a7d7dd..6b73469bb7 100644 --- a/rtl/inc/wustring22.inc +++ b/rtl/inc/wustring22.inc @@ -1434,18 +1434,10 @@ end; Procedure SetString (Out S : WideString; Buf : PWideChar; Len : SizeInt); -var - BufLen: SizeInt; begin SetLength(S,Len); If (Buf<>Nil) and (Len>0) then - begin - 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; + Move (Buf[0],S[1],Len*sizeof(WideChar)); end; diff --git a/tests/webtbs/tw14740.pp b/tests/webtbs/tw14740.pp new file mode 100644 index 0000000000..5ba9826728 --- /dev/null +++ b/tests/webtbs/tw14740.pp @@ -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.