Ver código fonte

Fix bug report 35937 by simple assembly code change and add test

git-svn-id: trunk@42603 -
pierre 6 anos atrás
pai
commit
008c1436d8
4 arquivos alterados com 75 adições e 6 exclusões
  1. 1 0
      .gitattributes
  2. 6 3
      rtl/powerpc/powerpc.inc
  3. 6 3
      rtl/powerpc64/powerpc64.inc
  4. 62 0
      tests/webtbs/tw35937.pp

+ 1 - 0
.gitattributes

@@ -17782,6 +17782,7 @@ tests/webtbs/tw35886.pp svneol=native#text/plain
 tests/webtbs/tw3589.pp svneol=native#text/plain
 tests/webtbs/tw35897.pp svneol=native#text/plain
 tests/webtbs/tw35918.pp svneol=native#text/pascal
+tests/webtbs/tw35937.pp svneol=native#text/plain
 tests/webtbs/tw3594.pp svneol=native#text/plain
 tests/webtbs/tw3595.pp svneol=native#text/plain
 tests/webtbs/tw3612.pp svneol=native#text/plain

+ 6 - 3
rtl/powerpc/powerpc.inc

@@ -1018,8 +1018,11 @@ asm
       mr      r10,r4
       mtctr   r10
       { at LStrPasDone, we set the length of the result to 255 - r10 - r4 }
-      { = 255 - 255 - 0 if the soure = nil -> perfect :)                  }
-      beq     .LStrPasDone
+      bne     .LStrPasStart
+      { put zero into r10 }
+      mr      r10, r8
+      b       .LStrPasDone
+.LStrPasStart:
       { save address for at the end and use r7 in loop }
       mr      r7,r3
       { no "subi r7,r7,1" because the first byte = length byte }
@@ -1037,11 +1040,11 @@ asm
       { if r10 was zero (-> stopped because of zero byte), then r4 will be 32 }
       { (32 leading zero bits) -> shr 5 = 1, otherwise this will be zero      }
       srwi    r4,r4,5
-.LStrPasDone:
       subfic  r10,r10,255
       sub     r10,r10,r4
 
       { store length }
+.LStrPasDone:
       stb     r10,0(r3)
 end;
 {$endif FPC_SYSTEM_HAS_FPC_PCHAR_TO_SHORTSTR}

+ 6 - 3
rtl/powerpc64/powerpc64.inc

@@ -509,8 +509,11 @@ asm
         mr      r10,r4
         mtctr   r10
         { at LStrPasDone, we set the length of the result to 255 - r10 - r4 }
-        { = 255 - 255 - 0 if the soure = nil -> perfect :)                  }
-        beq     .LStrPasDone
+        bne     .LStrPasStart
+        { put zero into r10 }
+        mr      r10, r8
+        b       .LStrPasDone
+.LStrPasStart:
         { save address for at the end and use r7 in loop }
         mr      r7,r3
         { no "subi r7,r7,1" because the first byte = length byte }
@@ -528,11 +531,11 @@ asm
         { if r10 was zero (-> stopped because of zero byte), then r4 will be 64 }
         { (64 leading zero bits) -> shr 6 = 1, otherwise this will be zero      }
         srdi    r4,r4,6
-.LStrPasDone:
         subfic  r10,r10,255
         sub     r10,r10,r4
 
         { store length }
+.LStrPasDone:
         stb     r10,0(r3)
 end;
 {$endif FPC_SYSTEM_HAS_FPC_PCHAR_TO_SHORTSTR}

+ 62 - 0
tests/webtbs/tw35937.pp

@@ -0,0 +1,62 @@
+
+
+uses
+  dos;
+
+var
+  s : string;
+  s50 : string[50];
+  s123 : string[123];
+  pp : ppchar;
+  p : pchar;
+  i, k,tot : longint;
+begin
+  tot:=0;
+  p:=nil;
+  s:='Dummy test 255';
+  writeln('s=',s);
+  s:=p;
+  i:=length(s);
+  writeln('Length of s is ',i);
+  if (i>0) then
+    begin
+      writeln('s=#',s,'#');
+      for k:=1 to i do
+        write(k,' #',ord(s[k]),' ');
+      writeln;
+      tot:=tot+i;
+    end;
+  s50:='Dummy test 50';
+  writeln('s50=',s50);
+  s50:=p;
+  i:=length(s50);
+  writeln('Length of s50 is ',i);
+  if (i>0) then
+    begin
+      writeln('s50=#',s50,'#');
+      for k:=1 to i do
+        write(k,' #',ord(s50[k]),' ');
+      writeln;
+      tot:=tot+i;
+    end;
+  s123:='Dummy test 255';
+  writeln('s123=',s123);
+  s123:=p;
+  i:=length(s123);
+  writeln('Length of s123 is ',i);
+  if (i>0) then
+    begin
+      writeln('s123=#',s123,'#');
+      for k:=1 to i do
+        write(k,' #',ord(s123[k]),' ');
+      writeln;
+      tot:=tot+i;
+    end;
+  if tot>0 then
+    begin
+      writeln('There are errors in the conversion of nil pchars to short strings');
+      halt(tot);
+    end;
+end.
+
+