diff options
author | charlet <charlet@138bc75d-0d04-0410-961f-82ee72b054a4> | 2015-01-06 09:53:40 +0000 |
---|---|---|
committer | charlet <charlet@138bc75d-0d04-0410-961f-82ee72b054a4> | 2015-01-06 09:53:40 +0000 |
commit | da7132b9db95271a7a97315d5da821d87f7a8afb (patch) | |
tree | c97bb16df64b364a5a9589a9fc4a6299e2b90dc9 /gcc/ada/s-valint.adb | |
parent | 9b442f464ac0deef3f40c5284525ab2ce172ce84 (diff) | |
download | gcc-da7132b9db95271a7a97315d5da821d87f7a8afb.tar.gz |
2015-01-06 Robert Dewar <dewar@adacore.com>
* s-valint.adb, s-valuns.adb (Value_Integer): Deal with case where
Str'Last = Positive'Last
2015-01-06 Thomas Quinot <quinot@adacore.com>
* xoscons.adb: Display exception information and return non-zero
exit status in top level exception handler.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@219242 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/ada/s-valint.adb')
-rw-r--r-- | gcc/ada/s-valint.adb | 30 |
1 files changed, 24 insertions, 6 deletions
diff --git a/gcc/ada/s-valint.adb b/gcc/ada/s-valint.adb index d77de09ef2f..25b9216b189 100644 --- a/gcc/ada/s-valint.adb +++ b/gcc/ada/s-valint.adb @@ -6,7 +6,7 @@ -- -- -- B o d y -- -- -- --- Copyright (C) 1992-2012, Free Software Foundation, Inc. -- +-- Copyright (C) 1992-2014, Free Software Foundation, Inc. -- -- -- -- GNAT is free software; you can redistribute it and/or modify it under -- -- terms of the GNU General Public License as published by the Free Soft- -- @@ -89,12 +89,30 @@ package body System.Val_Int is ------------------- function Value_Integer (Str : String) return Integer is - V : Integer; - P : aliased Integer := Str'First; begin - V := Scan_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_Integer (NT (Str)); + end; + + -- Normal case where Str'Last < Positive'Last + + else + declare + V : Integer; + P : aliased Integer := Str'First; + begin + V := Scan_Integer (Str, P'Access, Str'Length); + Scan_Trailing_Blanks (Str, P); + return V; + end; + end if; end Value_Integer; end System.Val_Int; |