From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1914) id A5460385842E; Tue, 21 Sep 2021 15:25:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A5460385842E MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Pierre-Marie de Rodat To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-3729] [Ada] Exception raised on empty file in GNATprove mode X-Act-Checkin: gcc X-Git-Author: Yannick Moy X-Git-Refname: refs/heads/master X-Git-Oldrev: c36332031cff305ceb0d1924ee4b2cedbd85023a X-Git-Newrev: ea3789f6a2b868d9f440ddece64142d3a2cbcf1c Message-Id: <20210921152558.A5460385842E@sourceware.org> Date: Tue, 21 Sep 2021 15:25:58 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 21 Sep 2021 15:25:58 -0000 https://gcc.gnu.org/g:ea3789f6a2b868d9f440ddece64142d3a2cbcf1c commit r12-3729-gea3789f6a2b868d9f440ddece64142d3a2cbcf1c Author: Yannick Moy Date: Thu Jul 1 09:36:53 2021 +0200 [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. Diff: --- gcc/ada/errout.adb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/gcc/ada/errout.adb b/gcc/ada/errout.adb index 0122304da6f..c859d8c5110 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;