https://gcc.gnu.org/g:434a5ff1e76d15a1802e1fe4f4029ddd41c5ee73
commit r16-1382-g434a5ff1e76d15a1802e1fe4f4029ddd41c5ee73 Author: Tonu Naks <n...@adacore.com> Date: Tue Mar 25 09:49:25 2025 +0000 ada: Special case for inconsistent pointer in Scan_Raw_Unsigned gcc/ada/ChangeLog: * libgnat/s-valueu.adb: add explict raise * libgnat/s-valueu.ads: update annotation Diff: --- gcc/ada/libgnat/s-valueu.adb | 9 +++++++++ gcc/ada/libgnat/s-valueu.ads | 8 +++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/gcc/ada/libgnat/s-valueu.adb b/gcc/ada/libgnat/s-valueu.adb index 72e73a8ce410..a27e00f1c6ae 100644 --- a/gcc/ada/libgnat/s-valueu.adb +++ b/gcc/ada/libgnat/s-valueu.adb @@ -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; diff --git a/gcc/ada/libgnat/s-valueu.ads b/gcc/ada/libgnat/s-valueu.ads index 0dc3399ba39b..488c342e6b82 100644 --- a/gcc/ada/libgnat/s-valueu.ads +++ b/gcc/ada/libgnat/s-valueu.ads @@ -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