[Bug ada/42974] New: Array slice assignment is missing bounds checking for the source array
tero dot koskinen at iki dot fi
gcc-bugzilla@gcc.gnu.org
Fri Feb 5 15:23:00 GMT 2010
GNAT does not generate dynamic/runtime bounds checking for array slice
assignment.
Following code should raise exception (but it doesn't):
-- gnatmake -gnatf -gnato testcase.adb
procedure Testcase is
type Element_Access is access all Integer;
type Element_Array is
array (Positive range <>) of Integer;
type Element_Array_Access is access all Element_Array;
A : Element_Array_Access := null;
B : Element_Array_Access := null;
begin
A := new Element_Array (1 .. 10);
A.all := (1,2,3,4,5,6,7,8,9,10);
B := new Element_Array (Positive'First .. Positive'First + 20);
B.all (Positive'First .. Positive'First + 15)
:= A.all (A.all'First .. A.all'First + 15);
end Testcase;
Two other commercial compilers raise exception when the program is run, but
GNAT doesn't.
Tested versions:
GNAT 4.3.2 on Debian GNU/Linux 5.0/stable (i386)
GNAT 4.4.2 on Fedora 12 (i386)
GNAT 4.2.4 on Ubuntu 8.04 (i386)
GNAT GPL 2009 on Windows XP (i386)
Example output from those commercial compilers:
-- first compiler
[C:\koodi\ada\buffer]testcase
** Unhandled CONSTRAINT_ERROR
Index or Subtype out of bounds - Pos of Error Value = 16
On Line Number 16 In TESTCASE
[C:\koodi\ada\buffer]
-- second compiler
[C:\koodi\ada\buffer]testcase
Ada-runtime: Exception CONSTRAINT_ERROR raised in
c:/koodi/ada/buffer/testcase.adb on line 16.
Bad bounds: 1..16 not in 1..10.
[C:\koodi\ada\buffer]
--
Summary: Array slice assignment is missing bounds checking for
the source array
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: major
Priority: P3
Component: ada
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: tero dot koskinen at iki dot fi
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42974
More information about the Gcc-bugs
mailing list