]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Special case for inconsistent pointer in Scan_Raw_Unsigned
authorTonu Naks <naks@adacore.com>
Tue, 25 Mar 2025 09:49:25 +0000 (09:49 +0000)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Tue, 10 Jun 2025 07:32:08 +0000 (09:32 +0200)
gcc/ada/ChangeLog:

* libgnat/s-valueu.adb: add explict raise
* libgnat/s-valueu.ads: update annotation

gcc/ada/libgnat/s-valueu.adb
gcc/ada/libgnat/s-valueu.ads

index 72e73a8ce410fe0e52253c757625128113974a66..a27e00f1c6ae54a69e657a74e5425a1fa3a249e0 100644 (file)
@@ -73,6 +73,15 @@ package body System.Value_U is
       end if;
 
       P := Ptr.all;
+
+      --  Exit when the initial string to parse is empty
+
+      if Max < P then
+         raise Program_Error with
+            "Scan end Max=" & Max'Img &
+            " is smaller than scan end Ptr=" & P'Img;
+      end if;
+
       Uval := Character'Pos (Str (P)) - Character'Pos ('0');
       pragma Assert (Str (P) in '0' .. '9');
       P := P + 1;
index 0dc3399ba39b25748ba5d14e078b0bb1dc6ec50e..488c342e6b82db2825286f356616be5374bb9927 100644 (file)
@@ -102,11 +102,9 @@ package System.Value_U is
    --  This string results in a Constraint_Error with the pointer pointing
    --  past the second 2.
    --
-   --  Note: if Str is empty, i.e. if Max is less than Ptr, then this is a
-   --  special case of an all-blank string, and Ptr is unchanged, and hence
-   --  is greater than Max as required in this case.
-   --  ??? This is not the case. We will read Str (Ptr.all) without checking
-   --  and increase Ptr.all by one.
+   --  Note: If Max is less than Ptr, then Ptr is left unchanged and
+   --  Program_Error is raised to indicate that a valid integer cannot
+   --  be parsed.
    --
    --  Note: this routine should not be called with Str'Last = Positive'Last.
    --  If this occurs Program_Error is raised with a message noting that this