Board index » kylix » Andreas: FastLinuxRTL is broken

Andreas: FastLinuxRTL is broken


2005-06-24 05:40:37 AM
kylix1
Andreas, while hunting down a strange bug (TStringList wasn't sorting entries
correctly), I found out that FastLinuxRTL has a {*word*193} bug:
In all the compare functions you assume that
if Len1 <>Len2 then
begin
if Len1 < Len2 then Result := -1 else Result := 1;
Exit;
end;
The routines you are replacing actually have the following behaviour:
"If the two strings are different lengths, they are compared up to the
length of the shortest one. If they are equivalent at that point, the
return value indicates that the longer string is greater. For more
information about locale identifiers, see Locales."
Whoever is currently using FastLinuxRTL should be aware of this issue.
It would be nice if you could fix this.
Thanks,
Simon
 
 

Re:Andreas: FastLinuxRTL is broken

Here is a patch:
100a101
Quote
sLen: integer;
122,126c123,124
< if Len1 <>Len2 then
< begin
< Result := Len1 - Len2;
< Exit;
< end;
---
Quote

if Len1<Len2 then sLen:=Len1 else sLen:=Len2;
130c128
< for i := 0 to Len1 - 1 do
---
Quote
for i := 0 to sLen - 1 do
148c146
< for i := 0 to Len1 - 1 do
---
Quote
for i := 0 to sLen - 1 do
225a224
sLen: Integer;
234,238d232
< if Len1 <>Len2 then
< begin
< if Len1 < Len2 then Result := -1 else Result := 1;
< Exit;
< end;
240c234,236
< for i := 0 to Len1 - 1 do
---
Quote
if Len1<Len2 then sLen:=Len1 else sLen:=Len2;

for i := 0 to sLen - 1 do
 

Re:Andreas: FastLinuxRTL is broken

Quote
Here is a patch:
....which still is incorrect. It now correctly compares strings up to the length of the
shorter one, but if they are equal till this point, it results that the strings
are identical. Instead in this case the longer string is the bigger one in this case.
Looks like those functions need a rewrite.
Simon
 

{smallsort}

Re:Andreas: FastLinuxRTL is broken

Simon Kissel wrote:
Quote
It would be nice if you could fix this.
This is now fixed. I don't know against what I tested these functions. I
only remember that I have changed the expected behaviour to return the
difference in the length of the strings. But I don't know why I had
changed that. Does wstrcoll() return such values? Because Windows's
CompareString()-2 returns only -1,0,1 and no size difference.
The new file is uploaded to the unvclx.sf.net homepage
--
Regards,
Andreas Hausladen
(www.kylix-patch.de.vu - unofficial Kylix 3 patches)
(andy.jgknet.de/blog)
 

Re:Andreas: FastLinuxRTL is broken

Andreas,
Quote
>It would be nice if you could fix this.

This is now fixed. I don't know against what I tested these functions. I
only remember that I have changed the expected behaviour to return the
difference in the length of the strings. But I don't know why I had
changed that. Does wstrcoll() return such values? Because Windows's
CompareString()-2 returns only -1,0,1 and no size difference.
The new file is uploaded to the unvclx.sf.net homepage
Thanks for the update. However it still seems to be incorrect - see my self-
reply to my patch. As I see it, the function now would return 0 if you
compare "wurst" and "wurst2".
In case the two strings have different sizes, you should compare using the
length of the shorter one. If the result of this is that to this point
both strings are equal, you then return 0 ONLY if those two strings have the
same length. If not, the longer one is bigger.
Probably simply replacing the last line containing "Result := 0;" with
if Len1 <>Len2 then
Result := Len1 - Len2;
else
Result := 0;
should do the trick.
Simon
 

Re:Andreas: FastLinuxRTL is broken

Simon Kissel wrote:
Quote
Thanks for the update.
However it still seems to be incorrect - see my self- reply to
my patch.
I haven't used your patch.
I have removed the "if Len1 <>Len2 then Exit" and iterate from "0 to
Max(Len1, Len2) -1". If one string ends it has an additional char #0 which
compared to everything else is always less and so the result is -1 if the
first string is shorter than the second (0-S2[i] < 0) and result is 1 if
thhe second string is shorter (S1[i]-0>0)
--
Regards,
Andreas Hausladen
(www.kylix-patch.de.vu - unofficial Kylix 3 patches)
(andy.jgknet.de/blog)
 

Re:Andreas: FastLinuxRTL is broken

Quote
I haven't used your patch.
I know.
Quote
I have removed the "if Len1 <>Len2 then Exit" and iterate from "0 to
Max(Len1, Len2) -1". If one string ends it has an additional char #0 which
compared to everything else is always less and so the result is -1 if the
first string is shorter than the second (0-S2[i] < 0) and result is 1 if
thhe second string is shorter (S1[i]-0>0)
Indeed, that's pretty clever. Thanks :)
Simon