[fpc-devel] Copy function and dynamic array

ik idokan at gmail.com
Wed Feb 29 13:54:40 CET 2012

On Wed, Feb 29, 2012 at 14:44, LacaK <lacak at zoznam.sk> wrote:
> Hi *,
> I found small incompatibility between Delphi and FPC.
> This code:
> var a,b: array of byte;
> begin
> 适适 setlength(a,2);
> 适适 b:=copy(a,2,1); //<--HERE "Range check error" in FPC, Delphi returns
> empty array
> end;
> Delphi documentation says:
> "If Index is larger than the length of S, Copy returns an empty string or
> array."
> http://docwiki.embarcadero.com/VCL/en/System.Copy
> Can it be fixed also in FPC?

I think it's a Delphi bug to act like that. You must provide a length
that is not bigger in size. It's up to you the developer.
Otherwise you might have more then one type of buffer overflows in your code !

The way Delphi solved it, is by taking the responsibility from the
developer, and made the code a bit slower.
And as I said, I don't think it's a good idea

> L.
> _______________________________________________
> fpc-devel maillist  -  fpc-devel at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-devel

More information about the fpc-devel mailing list