[Ada] Another small adjustment to System.Value_R
authorEric Botcazou <ebotcazou@adacore.com>
Fri, 27 Nov 2020 08:21:17 +0000 (09:21 +0100)
committerPierre-Marie de Rodat <derodat@adacore.com>
Wed, 16 Dec 2020 13:00:59 +0000 (08:00 -0500)
gcc/ada/

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

gcc/ada/libgnat/s-valuer.adb

index 9c126cc36226e4c3208aa797d7fe05d813172156..65a0d509e5a85fbc99e489cc11b4547ae043c0cb 100644 (file)
@@ -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;