summaryrefslogtreecommitdiff
path: root/gcc/ada/s-vallli.adb
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/ada/s-vallli.adb')
-rw-r--r--gcc/ada/s-vallli.adb28
1 files changed, 23 insertions, 5 deletions
diff --git a/gcc/ada/s-vallli.adb b/gcc/ada/s-vallli.adb
index 203e475b3cf..bf0e15d1234 100644
--- a/gcc/ada/s-vallli.adb
+++ b/gcc/ada/s-vallli.adb
@@ -91,12 +91,30 @@ package body System.Val_LLI is
-----------------------------
function Value_Long_Long_Integer (Str : String) return Long_Long_Integer is
- V : Long_Long_Integer;
- P : aliased Integer := Str'First;
begin
- V := Scan_Long_Long_Integer (Str, P'Access, Str'Last);
- Scan_Trailing_Blanks (Str, P);
- return V;
+ -- We have to special case Str'Last = Positive'Last because the normal
+ -- circuit ends up setting P to Str'Last + 1 which is out of bounds. We
+ -- deal with this by converting to a subtype which fixes the bounds.
+
+ if Str'Last = Positive'Last then
+ declare
+ subtype NT is String (1 .. Str'Length);
+ begin
+ return Value_Long_Long_Integer (NT (Str));
+ end;
+
+ -- Normal case where Str'Last < Positive'Last
+
+ else
+ declare
+ V : Long_Long_Integer;
+ P : aliased Integer := Str'First;
+ begin
+ V := Scan_Long_Long_Integer (Str, P'Access, Str'Last);
+ Scan_Trailing_Blanks (Str, P);
+ return V;
+ end;
+ end if;
end Value_Long_Long_Integer;
end System.Val_LLI;