]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
[Ada] Exception raised on empty file in GNATprove mode
authorYannick Moy <moy@adacore.com>
Thu, 1 Jul 2021 07:36:53 +0000 (09:36 +0200)
committerPierre-Marie de Rodat <derodat@adacore.com>
Tue, 21 Sep 2021 15:24:55 +0000 (15:24 +0000)
gcc/ada/

* errout.adb (Get_Line_End): Do not allow the result to go past
the end of the buffer.

gcc/ada/errout.adb

index 0122304da6ff5ebfd3bc851653c0f0b271c5aaa3..c859d8c5110ad3f9e0c2c7d99316412b91525cf2 100644 (file)
@@ -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;