[fpc-devel] sysstr patch once more
petr.kristan at epos.cz
petr.kristan at epos.cz
Tue May 6 11:10:08 CEST 2008
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 (Result<>0) 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 (Result<>0) 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
More information about the fpc-devel
mailing list