diff options
author | Piotr Trojanek <trojanek@adacore.com> | 2022-03-31 20:56:58 +0200 |
---|---|---|
committer | Pierre-Marie de Rodat <derodat@adacore.com> | 2022-05-18 08:41:01 +0000 |
commit | 16b8ba101f770503f363c095d7be5c055705b84b (patch) | |
tree | 95075cab4bf70f4cef9e7f06883460d63134bcc3 /gcc | |
parent | 8b49556e4ee617e0920a9335685c7961971c3d0a (diff) | |
download | gcc-16b8ba101f770503f363c095d7be5c055705b84b.zip gcc-16b8ba101f770503f363c095d7be5c055705b84b.tar.gz gcc-16b8ba101f770503f363c095d7be5c055705b84b.tar.bz2 |
[Ada] Prevent overflow in computation of aggregate size
When computing size of a static aggregate to decide if it should be
transformed into assignments and loops we could have an overflow check.
This is mostly harmless, because colossal aggregates will likely crash
the application anyway, no matter how we transform them.
This was not detected because compiler was built with -gnatg switch that
suppresses overflow checks (they are only enabled by an explicit -gnato
switch).
gcc/ada/
* exp_aggr.adb (Component_Count): Calculate size as an Uint and
only then check if it is in the range of Int, as otherwise the
multiplication of Int values can overflow.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/ada/exp_aggr.adb | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/gcc/ada/exp_aggr.adb b/gcc/ada/exp_aggr.adb index 72f6555..4714cab 100644 --- a/gcc/ada/exp_aggr.adb +++ b/gcc/ada/exp_aggr.adb @@ -661,10 +661,10 @@ package body Exp_Aggr is declare UI : constant Uint := - Expr_Value (Hi) - Expr_Value (Lo) + 1; + (Expr_Value (Hi) - Expr_Value (Lo) + 1) * Siz; begin if UI_Is_In_Int_Range (UI) then - return Siz * UI_To_Int (UI); + return UI_To_Int (UI); else return Int'Last; end if; |