Sfoglia il codice sorgente

* fixed crash when concatenating more than 2 ansistrings that are all empty
(mantis #25349, patch by C Western)

git-svn-id: trunk@26119 -

Jonas Maebe 11 anni fa
parent
commit
951727f453
3 ha cambiato i file con 31 aggiunte e 2 eliminazioni
  1. 1 0
      .gitattributes
  2. 7 2
      rtl/inc/astrings.inc
  3. 23 0
      tests/webtbs/tw25349.pp

+ 1 - 0
.gitattributes

@@ -13713,6 +13713,7 @@ tests/webtbs/tw25210.pp svneol=native#text/pascal
 tests/webtbs/tw2525.pp svneol=native#text/plain
 tests/webtbs/tw25269.pp svneol=native#text/pascal
 tests/webtbs/tw25318.pp svneol=native#text/pascal
+tests/webtbs/tw25349.pp svneol=native#text/plain
 tests/webtbs/tw2536.pp svneol=native#text/plain
 tests/webtbs/tw2540.pp svneol=native#text/plain
 tests/webtbs/tw2561.pp svneol=native#text/plain

+ 7 - 2
rtl/inc/astrings.inc

@@ -314,13 +314,18 @@ begin
 {$else FPC_HAS_CPSTRING}
   DestCP:=StringCodePage(DestS);
 {$endif FPC_HAS_CPSTRING}
-  DestCP:=TranslatePlaceholderCP(DestCP);
-  sameCP:=true;
   lowstart:=low(sarr);
   { skip empty strings }
   while (lowstart<=high(sarr)) and
         (sarr[lowstart]='') do
     inc(lowstart);
+  if lowstart>high(sarr) then
+    begin
+      DestS:=''; { All source strings empty }
+      exit;
+    end;
+  DestCP:=TranslatePlaceholderCP(DestCP);
+  sameCP:=true;
   tmpCP:=TranslatePlaceholderCP(StringCodePage(sarr[lowstart]));
   for i:=lowstart+1 to high(sarr) do
     begin

+ 23 - 0
tests/webtbs/tw25349.pp

@@ -0,0 +1,23 @@
+procedure trashstack;
+var
+  a: array[0..high(word)] of byte;
+begin
+  fillchar(a,sizeof(a),$ff);
+end;
+
+procedure test;
+var
+  s1,s2,s3,s4: ansistring;
+begin
+  s2:='';
+  s3:='';
+  s4:='';
+  s1:=s2+s3+s4;
+  if s1<>'' then
+    halt(1);
+end;
+
+begin
+  trashstack;
+  test;
+end.