Sign in Join

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

Mailing lists / fpc-devel / 2008-04

sysstr patch

3 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 comparing routines does not work correct if two strings were empty. Example:

program comp;
uses
   SysUtils;
var
  a, b: array[0..1] of char;
begin
  a[0] := #0;
  a[1] := #1;
  b[0] := #0;
  b[1] := #0;
  writeln(AnsiStrComp(a, b)=0); // '',''=0
end

This program returns false and theoreticaly repeat..until may SIGSEGV because overflows empty PChar boundary after first cycle.

Patch is in the attachment.

Petr

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

Micha Nelissen
to Unknown author
Show quoted text 6 lines
@@ -335,11 +336,12 @@ Result:=1; exit; end; - Repeat + While (Result=0) and (S1^#0) and (S2^#0) do

You only have to check one of S1 or S2 being unequal to zero. (Otherwise they would be different anyway).

Micha

Reply by email

Unknown author
to Micha Nelissen
Micha Nelissen wrote 10 lines
wrote: > @@ -335,11 +336,12 @@ > Result:=1; > exit; > end; > - Repeat > + While (Result=0) and (S1^#0) and (S2^#0) do You only have to check one of S1 or S2 being unequal to zero. (Otherwise they would be different anyway).

And what about case S1='' and S2='' in the first check?

Petr

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