[fpc-devel]A bug

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

>         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;
>         adddata (pointer(a)^,length (a));
>         Cl: TCl;
>         Cl := TCl.create;
>writeln (cl.a);
>   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 ?


More information about the fpc-devel mailing list