Sfoglia il codice sorgente

* fixed another bug in fpc_ansistr_append_ansistring in case source = dest
(web bug #4999)

git-svn-id: trunk@3185 -

Jonas Maebe 19 anni fa
parent
commit
72b75a627a
3 ha cambiato i file con 21 aggiunte e 2 eliminazioni
  1. 1 0
      .gitattributes
  2. 8 2
      rtl/inc/astrings.inc
  3. 12 0
      tests/webtbs/tw4999.pp

+ 1 - 0
.gitattributes

@@ -6779,6 +6779,7 @@ tests/webtbs/tw4898.pp -text
 tests/webtbs/tw4902.pp -text
 tests/webtbs/tw4922.pp svneol=native#text/plain
 tests/webtbs/tw4950.pp svneol=native#text/plain
+tests/webtbs/tw4999.pp svneol=native#text/plain
 tests/webtbs/ub1873.pp svneol=native#text/plain
 tests/webtbs/ub1883.pp svneol=native#text/plain
 tests/webtbs/uw0555.pp svneol=native#text/plain

+ 8 - 2
rtl/inc/astrings.inc

@@ -503,16 +503,22 @@ end;
 
 Procedure fpc_ansistr_append_ansistring(Var S : AnsiString;const Str : AnsiString); [Public,Alias : 'FPC_ANSISTR_APPEND_ANSISTRING']; compilerproc;
 var
-   ofs, strlength : SizeInt;
+   ofs, strlength: SizeInt;
+   samestring: boolean;
 begin
    if Str='' then
      exit;
+   samestring := pointer(s) = pointer(str);
    { needed in case s and str are the same string }
    strlength := length(str);
    ofs:=Length(S);
    SetLength(S,ofs+strlength);
    { the pbyte cast avoids an unique call which isn't necessary because SetLength was just called }
-   move(Str[1],(pointer(S)+ofs)^,strlength+1);
+   if not(samestring) then
+     move(Str[1],(pointer(S)+ofs)^,strlength+1)
+   else
+     { the setlength may have relocated the string, so str may no longer be valid }
+     move(S[1],(pointer(S)+ofs)^,strlength+1)
 end;
 
 Function Fpc_Ansistr_Copy (Const S : AnsiString; Index,Size : SizeInt) : AnsiString;compilerproc;

+ 12 - 0
tests/webtbs/tw4999.pp

@@ -0,0 +1,12 @@
+program fpc203fish;
+{$mode objfpc}{$H+}
+uses  Classes;
+var    s:String;
+       i:integer;
+begin
+ s:='123123sdfjkysdjfklsdn3m,w45';
+ for i:=0 to 22 do begin
+  s:=s+s;
+  writeln(i);
+ end;
+end.