[fpc-devel] Copy function and dynamic array
zeljko at holobit.net
Wed Feb 29 14:06:43 CET 2012
On Wednesday 29 of February 2012 13:54:40 ik wrote:
> 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
+1 ... @lacak, better fix your code. I don't like to be delphi compatibile
with such things.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the fpc-devel