Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2008-05

sysstr patch once more

2 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Unknown author

Hi.

sysstr.inc r10846 does not include my patch, which solves problem when both strings are empty and differs after null character. Then I'am sending it again merged against trunk.

Here is testcase:

program comp;
uses
   SysUtils;
var
  a, b: array[0..1] of char;
begin
  a[0] := #0; a[1] := #1; //Empty string
  b[0] := #0; b[1] := #0; //Empty string with different char after end
  writeln(AnsiStrComp(a, b)); //should be zero because a=b
  writeln(AnsiStrIComp(a, b)); /should be zero because a=b
end.

And here is patch. Construction with "repeat" overflows strings boundary in the first cycle, "while" solves this problem. The same construction is used in GenericAnsiCompareText.

Index: rtl/objpas/sysutils/sysstr.inc
===================================================================
--- rtl/objpas/sysutils/sysstr.inc      (revision 10891)
+++ rtl/objpas/sysutils/sysstr.inc      (working copy)
@@ -307,11 +307,11 @@
       Result:=1;
       exit;
     end;
-  Repeat
+  While (Result=0) and (S1^#0) and (S2^#0) do begin
     Result:=Ord(S1^)-Ord(S2^); //!! Must be replaced by ansi characters !!
     Inc(S1);
     Inc(S2);
-  Until (Result0) or (S1^=#0) or (S2^=#0);
+  end;
   if (Result=0) and (S1^S2^) then // loop ended because exactly one has #0
     if S1^=#0 then // shorter string is smaller
       result:=-1
@@ -335,11 +335,11 @@
     Result:=1;
     exit;
     end;
-  Repeat
+  While (Result=0) and (S1^#0) and (S2^#0) do begin
     Result:=Ord(LowerCaseTable[Ord(S1[0])])-Ord(LowerCaseTable[Ord(S2[0])]); //!! Must be replaced by ansi characters !!
     Inc(S1);
     Inc(S2);
-  Until (Result0) or ((S1[0]=#0) or (S2[0]=#0));
+  end;
   if (Result=0) and (s1[0]s2[0]) then //length(s1)length(s2)
     if s1[0]=#0 then
       Result:=-1 //s1 shorter than s2
Ing. Petr Kristan . EPOS PRO s.r.o., Bozeny Nemcove 2625, 530 02 Pardubice tel: +420 466335223 Czech Republic (Eastern Europe) fax: +420 466510709

Reply by email

Jonas Maebe
to Unknown author
sysstr.inc r10846 does not include my patch, which solves problem when both strings are empty and differs after null character. Then I'am sending it again merged against trunk.

Just a small note: this routine is only used on Dos, OS/2 and other platforms without a widestring manager. If you are working under *nix, add the cwstring unit to your uses clause to get a real widestring manager (based on libc/libiconv) with codepage-aware conversions/ comparisons.

Jonas

Reply by email