Browse Source

* 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 -

Jonas Maebe 16 years ago
parent
commit
6a0755e897
5 changed files with 20 additions and 27 deletions
  1. 1 0
      .gitattributes
  2. 1 9
      rtl/inc/ustrings.inc
  3. 1 9
      rtl/inc/wstrings.inc
  4. 1 9
      rtl/inc/wustring22.inc
  5. 16 0
      tests/webtbs/tw14740.pp

+ 1 - 0
.gitattributes

@@ -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

+ 1 - 9
rtl/inc/ustrings.inc

@@ -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
-      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;
 end;
 
 
 
 

+ 1 - 9
rtl/inc/wstrings.inc

@@ -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
-      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;
 end;
 
 
 
 

+ 1 - 9
rtl/inc/wustring22.inc

@@ -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
-      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;
 end;
 
 
 
 

+ 16 - 0
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.