[fpc-devel] Copy function and dynamic array

2012-02-29 Thread LacaK
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

Re: [fpc-devel] Copy function and dynamic array

2012-02-29 Thread ik
On Wed, Feb 29, 2012 at 14:44, LacaK la...@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

Re: [fpc-devel] Copy function and dynamic array

2012-02-29 Thread Sven Barth
Am 29.02.2012 13:54, schrieb ik: On Wed, Feb 29, 2012 at 14:44, LacaKla...@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

Re: [fpc-devel] Copy function and dynamic array

2012-02-29 Thread zeljko
On Wednesday 29 of February 2012 13:54:40 ik wrote: On Wed, Feb 29, 2012 at 14:44, LacaK la...@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

RE : [fpc-devel] Copy function and dynamic array

2012-02-29 Thread Ludo Brands
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

Re: [fpc-devel] Copy function and dynamic array

2012-02-29 Thread Sergei Gorelkin
29.02.2012 17:05, Sven Barth пишет: 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). It cannot be fixed for Delphi mode only because a single copy of RTL is used for all compiler modes. The

Re: RE : [fpc-devel] Copy function and dynamic array

2012-02-29 Thread kyan
In the mean time there is tons of code that relies on copy() copying until end of string or dynamic array. Constructions like param=copy(s,pos('=')+1,length(s)) are plenty. Just do a grep in the fpc compiler dir for copy( and you'l find plenty of copy(s,p+1,255) and the like. Second that, In

Re: [fpc-devel] Copy function and dynamic array

2012-02-29 Thread Sven Barth
Am 29.02.2012 14:31, schrieb Sergei Gorelkin: 29.02.2012 17:05, Sven Barth пишет: 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). It cannot be fixed for Delphi mode only because a single copy of

Re: [fpc-devel] Copy function and dynamic array

2012-02-29 Thread LacaK
Sergei Gorelkin wrote / napísal(a): 29.02.2012 17:05, Sven Barth пишет: 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). It cannot be fixed for Delphi mode only because a single copy of RTL is

Re: [fpc-devel] Copy function and dynamic array

2012-02-29 Thread Sergei Gorelkin
29.02.2012 18:21, LacaK пишет: It cannot be fixed for Delphi mode only because a single copy of RTL is used for all compiler modes. The current situation where out of range 'length' parameter is adjusted but 'index' out of range raises exception is simply self-inconsistent. It is also

Re: [fpc-devel] Copy function and dynamic array

2012-02-29 Thread Hans-Peter Diettrich
ik schrieb: 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

Re: [fpc-devel] Copy function and dynamic array

2012-02-29 Thread Martin Schreiber
Am 29.02.2012 14:31, schrieb Sergei Gorelkin: The current situation where out of range 'length' parameter is adjusted but 'index' out of range raises exception is simply self-inconsistent. It is also inconsistent with behavior of Copy for strings. Adjusting index will neither cause any buffer

Re: [fpc-devel] Copy function and dynamic array

2012-02-29 Thread LacaK
Sergei Gorelkin wrote / napísal(a): 29.02.2012 18:21, LacaK пишет: It cannot be fixed for Delphi mode only because a single copy of RTL is used for all compiler modes. The current situation where out of range 'length' parameter is adjusted but 'index' out of range raises exception is simply