aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorYannick Moy <moy@adacore.com>2021-07-01 09:36:53 +0200
committerPierre-Marie de Rodat <derodat@adacore.com>2021-09-21 15:24:55 +0000
commitea3789f6a2b868d9f440ddece64142d3a2cbcf1c (patch)
tree41deef275a70cfffc9ac717dec04de711ab99619 /gcc
parentc36332031cff305ceb0d1924ee4b2cedbd85023a (diff)
downloadgcc-ea3789f6a2b868d9f440ddece64142d3a2cbcf1c.zip
gcc-ea3789f6a2b868d9f440ddece64142d3a2cbcf1c.tar.gz
gcc-ea3789f6a2b868d9f440ddece64142d3a2cbcf1c.tar.bz2
[Ada] Exception raised on empty file in GNATprove mode
gcc/ada/ * errout.adb (Get_Line_End): Do not allow the result to go past the end of the buffer.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ada/errout.adb7
1 files changed, 4 insertions, 3 deletions
diff --git a/gcc/ada/errout.adb b/gcc/ada/errout.adb
index 0122304..c859d8c 100644
--- a/gcc/ada/errout.adb
+++ b/gcc/ada/errout.adb
@@ -2473,7 +2473,8 @@ package body Errout is
function Get_Line_End
(Buf : Source_Buffer_Ptr;
Loc : Source_Ptr) return Source_Ptr;
- -- Get the source location for the end of the line in Buf for Loc
+ -- Get the source location for the end of the line in Buf for Loc. If
+ -- Loc is past the end of Buf already, return Buf'Last.
function Get_Line_Start
(Buf : Source_Buffer_Ptr;
@@ -2515,9 +2516,9 @@ package body Errout is
(Buf : Source_Buffer_Ptr;
Loc : Source_Ptr) return Source_Ptr
is
- Cur_Loc : Source_Ptr := Loc;
+ Cur_Loc : Source_Ptr := Source_Ptr'Min (Loc, Buf'Last);
begin
- while Cur_Loc <= Buf'Last
+ while Cur_Loc < Buf'Last
and then Buf (Cur_Loc) /= ASCII.LF
loop
Cur_Loc := Cur_Loc + 1;