[fpc-devel]A bug

Peter Vreman peter at freepascal.org
Fri Jun 1 23:21:31 CEST 2001


>
>type
>         TCl = class
>                 public
>                         a: AnsiString;
>
>                         procedure load;
>                 end;
>
>procedure TCl.load;
>
>         procedure adddata (var buffer; l: dword);
>         begin
>                 setlength (a, length (a) + l);
>                 move (buffer, (pointer (a) + length (a))^, l);
>         end;
>
>begin
>         adddata (pointer(a)^,length (a));
>end;
>
>var
>         Cl: TCl;
>
>begin
>         Cl := TCl.create;
>cl.a:='34343';
>cl.load;
>cl.load;
>writeln (cl.a);
>end.
>--------
>
>   Seems to be that in "adddata" variable "a" is handled somehow
>   incorrectly or something...

This is not a bug in the compiler or RTL. Your code is wrong because it 
assumes that the setlength doesn't change the pointer of an ansistring 
which is not true. When setlength requires more space it can be necessary 
to allocate a new memory block elsewhere in the memory.


>   There is also an inline problem in v1.1. That was for some time
>   solved and now it appered again.

Which bug ?


Peter





More information about the fpc-devel mailing list