[fpc-devel] Copy function and dynamic array

Sven Barth pascaldragon at googlemail.com
Wed Feb 29 14:05:38 CET 2012


Am 29.02.2012 13:54, schrieb ik:
> 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

It's not a bug in Delphi if they write it in the documentation. Whether 
we should copy this behavior is the question (maybe only in Delphi mode).

Regards,
Sven




More information about the fpc-devel mailing list