From patchwork Wed Apr 27 12:31:07 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud Charlet X-Patchwork-Id: 615598 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 3qvzps3sdwz9t3w for ; Wed, 27 Apr 2016 22:31:33 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=d17c/3Ru; 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=sRLE9YvX5r/7cHt0BKiyTEwMn3FSWaoL5tMlE/a9sP8WNm7U8U k5+C9CNUYWeEi4cQA47StlSbDFlUz/53ykzoWLO/EvK0n14CQ5RJhIKFbSf76KOt 5lrWfFK/X6C4bJOfF3filEM/xBrx6sQdsE4EeGtOFUDLAc/Ap30lf9/IE= 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=wxf1OLvKVb54GndWWt0RpQZosUU=; b=d17c/3RukhKE9jXRgLGZ LoAvQrjngIKZpKgtVy+bvwjNrmDRpfLoOKHc7ygX5cWzs3PHFj7UEW980hqhq1iF SWHuPPgzczZJ6wr2UY19QzbfVN2YS7n68WrKUz2Hkpqfpff3N+IhJNy8LhFpFauh TYOS18luFlw/oeHkc/XAjVY= Received: (qmail 38947 invoked by alias); 27 Apr 2016 12:31:14 -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 38763 invoked by uid 89); 27 Apr 2016 12:31:10 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.1 required=5.0 tests=BAYES_00, KAM_ASCII_DIVIDERS, KAM_LAZY_DOMAIN_SECURITY, RCVD_IN_DNSWL_NONE autolearn=no version=3.3.2 spammy=elsif, 235481, thereof, col 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; Wed, 27 Apr 2016 12:31:09 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 6EBC6116CCB; Wed, 27 Apr 2016 08:31:07 -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 5REZNZYMazsP; Wed, 27 Apr 2016 08:31:07 -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 5F246116CC7; Wed, 27 Apr 2016 08:31:07 -0400 (EDT) Received: by tron.gnat.com (Postfix, from userid 4192) id 5B1C5370; Wed, 27 Apr 2016 08:31:07 -0400 (EDT) Date: Wed, 27 Apr 2016 08:31:07 -0400 From: Arnaud Charlet To: gcc-patches@gcc.gnu.org Cc: Ed Schonberg Subject: [Ada] Spurious End_Error with Get_Line on strings without line terminators Message-ID: <20160427123107.GA27989@adacore.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) This patch fixes a spurious End_Error raised by Text_IO.Get_Line, when the input line has 499 or 500 characters and does not contain a line terminator. No short example available. Tested on x86_64-pc-linux-gnu, committed on trunk 2016-04-27 Ed Schonberg * a-textio.adb (Get_Line function): Handle properly the case of a line that has the same length as the buffer (or a multiple thereof) and there is no line terminator. * a-tigeli.adb (Get_Line procedure): Do not store an end_of_file in the string when there is no previous line terminator and we need at most one additional character. Index: a-textio.adb =================================================================== --- a-textio.adb (revision 235481) +++ a-textio.adb (working copy) @@ -6,7 +6,7 @@ -- -- -- B o d y -- -- -- --- Copyright (C) 1992-2015, Free Software Foundation, Inc. -- +-- Copyright (C) 1992-2016, 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- -- @@ -704,9 +704,6 @@ end Get_Line; function Get_Line (File : File_Type) return String is - Buffer : String (1 .. 500); - Last : Natural; - function Get_Rest (S : String) return String; -- This is a recursive function that reads the rest of the line and -- returns it. S is the part read so far. @@ -732,12 +729,19 @@ begin if Last < Buffer'Last then return R; + else return Get_Rest (R); end if; end; end Get_Rest; + -- Local variables + + Buffer : String (1 .. 500); + ch : int; + Last : Natural; + -- Start of processing for Get_Line begin @@ -745,6 +749,22 @@ if Last < Buffer'Last then return Buffer (1 .. Last); + + -- If the String has the same length as the buffer, and there is no end + -- of line, check whether we are at the end of file, in which case we + -- have the full String in the buffer. + + elsif Last = Buffer'Last then + ch := Getc (File); + + if ch = EOF then + return Buffer; + + else + Ungetc (ch, File); + return Get_Rest (Buffer (1 .. Last)); + end if; + else return Get_Rest (Buffer (1 .. Last)); end if; Index: a-tigeli.adb =================================================================== --- a-tigeli.adb (revision 235481) +++ a-tigeli.adb (working copy) @@ -6,7 +6,7 @@ -- -- -- B o d y -- -- -- --- Copyright (C) 1992-2015, Free Software Foundation, Inc. -- +-- Copyright (C) 1992-2016, 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- -- @@ -187,9 +187,14 @@ -- If we get EOF after already reading data, this is an incomplete -- last line, in which case no End_Error should be raised. - if ch = EOF and then Last < Item'First then - raise End_Error; + if ch = EOF then + if Last < Item'First then + raise End_Error; + else -- All done + return; + end if; + elsif ch /= LM then -- Buffer really is full without having seen LM, update col