Copy function with dynamic arrays raises exception when starting index is higher than high index of copied array
Original Reporter info from Mantis: lacak @lacak.sk
-
Reporter name: LacaK
Original Reporter info from Mantis: lacak @lacak.sk
- Reporter name: LacaK
Description:
This behavior is incompatible with Delphi, where in situation when Index is > high index Copy function returns empty array.
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
Looking into function fpc_dynarray_copy in dynarr.inc:
{ get number of elements and check for invalid values }
+ if (lowidx > realpsrc^.high) then
+ exit;
- if (lowidx<0) or (highidx<0) or (lowidx > realpsrc^.high) then
+ if (lowidx<0) or (highidx<0) then
HandleErrorFrame(201,get_frame);
Steps to reproduce:
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;
Mantis conversion info:
- Mantis ID: 21396
- Version: 2.6.1
- Fixed in version: 3.0.0
- Fixed in revision: 20468 (#92f92797)