From: Tonu Naks <n...@adacore.com> gcc/ada/ChangeLog:
* libgnat/s-valueu.adb: add explict raise * libgnat/s-valueu.ads: update annotation Tested on x86_64-pc-linux-gnu, committed on master. --- 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 72e73a8ce41..a27e00f1c6a 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 0dc3399ba39..488c342e6b8 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 -- 2.43.0