From patchwork Mon May 2 09:11:09 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud Charlet X-Patchwork-Id: 617426 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3qyz832XVfz9t43 for ; Mon, 2 May 2016 19:11:32 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=Y5HewXNR; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:mime-version:content-type; q=dns; s=default; b=A/bvSOQIMImMGNOuBX5HkZubvYNKIukHyvLd7zK+TUrb7AcVh3 ev7IpolfDiBv+jYX3YnWH4Ho+InpDY5uU1+aPoAJVMqyGOug9cWbCMPUHoSp+tQp go9XCywPvokysILA9EDDnDqM1kYoY2VUhUW2BsBErfc/U96LUkNt1puUI= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:mime-version:content-type; s= default; bh=Isu8eTmubk6iJtgXa8P4rxjR8ws=; b=Y5HewXNRdLIZ14p8zTPj SeBPHJFhh3qOel4oHOhZMyENiURCi7J7GULiulvAbnIi38zHnXTQm7RKcHWQNugJ jqHqqZ8agXqwUhWAqlnKq594/Kdhih86Qkcps71q5g/aAntyUomLKkL84NtjzZ0e SGx5AJAWNsC9tn6kG0mZ/TE= Received: (qmail 126545 invoked by alias); 2 May 2016 09:11:21 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 126512 invoked by uid 89); 2 May 2016 09:11:21 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=0.6 required=5.0 tests=BAYES_00, COMPENSATION, KAM_LAZY_DOMAIN_SECURITY, RCVD_IN_DNSWL_NONE autolearn=no version=3.3.2 spammy=Natural, Hx-languages-length:1414, HX-Envelope-From:sk:charlet, H*F:U*charlet X-HELO: rock.gnat.com Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Mon, 02 May 2016 09:11:11 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 677BE116B42; Mon, 2 May 2016 05:11:09 -0400 (EDT) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id N4s3tASWiJjz; Mon, 2 May 2016 05:11:09 -0400 (EDT) Received: from tron.gnat.com (tron.gnat.com [IPv6:2620:20:4000:0:46a8:42ff:fe0e:e294]) by rock.gnat.com (Postfix) with ESMTP id 4F0AE116B3F; Mon, 2 May 2016 05:11:09 -0400 (EDT) Received: by tron.gnat.com (Postfix, from userid 4192) id 4B8D841B; Mon, 2 May 2016 05:11:09 -0400 (EDT) Date: Mon, 2 May 2016 05:11:09 -0400 From: Arnaud Charlet To: gcc-patches@gcc.gnu.org Cc: Yannick Moy Subject: [Ada] Fix bug on Get_Line when incomplete last line in file Message-ID: <20160502091109.GA61088@adacore.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) It may occur in some occasions that Get_Line incorrectly sets its Last parameter to one past the correct value. This can only occur when the line being copied is the last line of the file, and does not contain the newline character. Tested on x86_64-pc-linux-gnu, committed on trunk 2016-05-02 Yannick Moy * a-tigeli.adb (Get_Line): Fix bound for test to decide when to compensate for character 0 added by call to fgets. Index: a-tigeli.adb =================================================================== --- a-tigeli.adb (revision 235706) +++ a-tigeli.adb (working copy) @@ -120,10 +120,15 @@ K : Natural := Natural (P - S); begin - -- Now Buf (K + 2) should be 0, or otherwise Buf (K) is the 0 - -- put in by fgets, so compensate. + -- If K + 2 is greater than N, then Buf (K + 1) cannot be a LM + -- character from the source file, as the call to fgets copied at + -- most N - 1 characters. Otherwise, either LM is a character from + -- the source file and then Buf (K + 2) should be 0, or LM is a + -- character put in Buf by memset and then Buf (K) is the 0 put in + -- by fgets. In both cases where LM does not come from the source + -- file, compensate. - if K + 2 > Buf'Last or else Buf (K + 2) /= ASCII.NUL then + if K + 2 > N or else Buf (K + 2) /= ASCII.NUL then -- Incomplete last line, so remove the extra 0