diff mbox series

[Ada] Another small adjustment to System.Value_R

Message ID 20201216131534.GA69687@adacore.com
State New
Headers show
Series [Ada] Another small adjustment to System.Value_R | expand

Commit Message

Pierre-Marie de Rodat Dec. 16, 2020, 1:15 p.m. UTC
This makes the code more explicit for the sake of static analyzers.

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

gcc/ada/

	* libgnat/s-valuer.adb (Scan_Decimal_Digits): Tweak overflow test.
	(Scan_Integral_Digits): Likewise.
diff mbox series

Patch

diff --git a/gcc/ada/libgnat/s-valuer.adb b/gcc/ada/libgnat/s-valuer.adb
--- a/gcc/ada/libgnat/s-valuer.adb
+++ b/gcc/ada/libgnat/s-valuer.adb
@@ -236,12 +236,15 @@  package body System.Value_R is
                Temp := Value * Uns (Base) + Uns (Digit);
 
                --  Check if Temp is larger than Precision_Limit, taking into
-               --  account that Temp may have wrapped around.
+               --  account that Temp may wrap around when Precision_Limit is
+               --  equal to the largest integer.
 
                if Value <= Umax
                  or else (Value <= UmaxB
-                           and then Temp <= Precision_Limit
-                           and then Temp >= Uns (Base))
+                           and then ((Precision_Limit < Uns'Last
+                                       and then Temp <= Precision_Limit)
+                                     or else (Precision_Limit = Uns'Last
+                                               and then Temp >= Uns (Base))))
                then
                   Value := Temp;
                   Scale := Scale - 1;
@@ -386,12 +389,15 @@  package body System.Value_R is
             Temp := Value * Uns (Base) + Uns (Digit);
 
             --  Check if Temp is larger than Precision_Limit, taking into
-            --  account that Temp may have wrapped around.
+            --  account that Temp may wrap around when Precision_Limit is
+            --  equal to the largest integer.
 
             if Value <= Umax
               or else (Value <= UmaxB
-                        and then Temp <= Precision_Limit
-                        and then Temp >= Uns (Base))
+                        and then ((Precision_Limit < Uns'Last
+                                    and then Temp <= Precision_Limit)
+                                  or else (Precision_Limit = Uns'Last
+                                            and then Temp >= Uns (Base))))
             then
                Value := Temp;