]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
[Ada] Fix problematic underflow for Float_Type'Value
authorEric Botcazou <ebotcazou@adacore.com>
Mon, 4 Apr 2022 21:16:53 +0000 (23:16 +0200)
committerPierre-Marie de Rodat <derodat@adacore.com>
Wed, 18 May 2022 08:41:03 +0000 (08:41 +0000)
We need a couple of guards for boundary conditions in the support code.

gcc/ada/

* libgnat/s-dourea.adb ("/"): Add guard for zero and infinite
divisor.
* libgnat/s-valuer.adb (Scan_Raw_Real): Add guard for very large
exponent values.

gcc/ada/libgnat/s-dourea.adb
gcc/ada/libgnat/s-valuer.adb

index a6cf2a1ca0be421721d0dd691d45681fa24e0bf3..4f378d6cb6d8eda75ca370521a5c4edca024d86b 100644 (file)
@@ -178,6 +178,12 @@ package body System.Double_Real is
       P, R   : Double_T;
 
    begin
+      if Is_Infinity (B) or else Is_Zero (B) then
+         return (A.Hi / B, 0.0);
+      end if;
+      pragma Annotate (CodePeer, Intentional, "test always false",
+                       "code deals with infinity");
+
       Q1 := A.Hi / B;
 
       --  Compute R = A - B * Q1
@@ -196,6 +202,12 @@ package body System.Double_Real is
       R, S       : Double_T;
 
    begin
+      if Is_Infinity (B.Hi) or else Is_Zero (B.Hi) then
+         return (A.Hi / B.Hi, 0.0);
+      end if;
+      pragma Annotate (CodePeer, Intentional, "test always false",
+                       "code deals with infinity");
+
       Q1 := A.Hi / B.Hi;
       R := A - B * Q1;
 
index 4b4e8873c3e4fdd2d3bcbb5578db6392e9418ccc..b474f8429e52f51e5f34fa97633b4354ecf07e3c 100644 (file)
@@ -645,7 +645,14 @@ package body System.Value_R is
 
       Ptr.all := Index;
       Scan_Exponent (Str, Ptr, Max, Expon, Real => True);
-      Scale := Scale + Expon;
+
+      --  Handle very large exponents like Scan_Exponent
+
+      if Expon < Integer'First / 10 or else Expon > Integer'Last / 10 then
+         Scale := Expon;
+      else
+         Scale := Scale + Expon;
+      end if;
 
       --  Here is where we check for a bad based number