diff mbox series

[Ada] Missing check for assigning too-large array to fixed-lower-bound object

Message ID 20210618083827.GA129678@adacore.com
State New
Headers show
Series [Ada] Missing check for assigning too-large array to fixed-lower-bound object | expand

Commit Message

Pierre-Marie de Rodat June 18, 2021, 8:38 a.m. UTC
The compiler was failing to perform a check on a conversion of an
array that has a length that exceeds the range of the index subtype
of the target subtype of the conversion when the target subtype is an
unconstrained array subtype with a fixed lower bound (FLB). The FLB
array subtype's index range had its subtype set to the base type of the
parent array type's index subtype rather than the index subtype itself,
resulting in failure to impose a proper range check on the conversion.

Tested on x86_64-pc-linux-gnu, committed on trunk

gcc/ada/

	* sem_ch3.adb (Constrain_Index): Set the High_Bound of a
	fixed-lower-bound subtype's range to T (the subtype of the FLB
	index being constrained) rather than Base_Type (T).
diff mbox series

Patch

diff --git a/gcc/ada/sem_ch3.adb b/gcc/ada/sem_ch3.adb
--- a/gcc/ada/sem_ch3.adb
+++ b/gcc/ada/sem_ch3.adb
@@ -14397,7 +14397,7 @@  package body Sem_Ch3 is
 
       --  If this is a range for a fixed-lower-bound subtype, then set the
       --  index itype's lower bound to the FLB and the index type's upper bound
-      --  to the high bound of the index base type's high bound, mark the itype
+      --  to the high bound of the index subtype's high bound, mark the itype
       --  as an FLB index subtype, and set the range's Etype to the itype.
 
       if Nkind (S) = N_Range and then Is_FLB_Index then
@@ -14405,7 +14405,7 @@  package body Sem_Ch3 is
            (Def_Id,
             Make_Range (Sloc (S),
               Low_Bound  => Low_Bound (S),
-              High_Bound => Type_High_Bound (Base_Type (T))));
+              High_Bound => Type_High_Bound (T)));
          Set_Is_Fixed_Lower_Bound_Index_Subtype (Def_Id);
 
       else