From patchwork Mon Jun 21 13:27:04 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [Ada] Fixed I/O to a string X-Patchwork-Submitter: Arnaud Charlet X-Patchwork-Id: 56313 Message-Id: <20100621132704.GA20235@adacore.com> To: gcc-patches@gcc.gnu.org Cc: Ed Schonberg Date: Mon, 21 Jun 2010 15:27:04 +0200 From: Arnaud Charlet List-Id: This patch fixes an error in the handling of bounds when performing Fixed_IO to a string rather than to a file. The Fore parameter in this case is not bound by line length but depends only on the bounds of the target string. The following must compile and execute quietly: with Text_IO; procedure Test_Duration_Io is package Duration_Io is new Text_IO.Fixed_IO (Num => Duration); My_Duration : Duration; My_Output_String: String(1..300); begin My_Duration := 10.0; Duration_Io.Put(To=>My_Output_String, Item=>My_Duration); end Test_Duration_Io; Tested on x86_64-pc-linux-gnu, committed on trunk 2010-06-21 Ed Schonberg * a-tifiio.adb (Put): In the procedure that performs I/O on a String, Fore is not bound by line length. The Fore parameter of the internal procedure that performs the operation is an integer. Index: a-tifiio.adb =================================================================== --- a-tifiio.adb (revision 161073) +++ a-tifiio.adb (working copy) @@ -6,7 +6,7 @@ -- -- -- B o d y -- -- -- --- Copyright (C) 1992-2009, Free Software Foundation, Inc. -- +-- Copyright (C) 1992-2010, 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- -- @@ -301,10 +301,14 @@ package body Ada.Text_IO.Fixed_IO is (To : out String; Last : out Natural; Item : Num; - Fore : Field; + Fore : Integer; Aft : Field; Exp : Field); -- Actual output function, used internally by all other Put routines + -- The formal Fore is an Integer, not a Field, because the routine is + -- also called from the version of Put that performs I/O to a string, + -- where the starting position depends on the size of the String, and + -- bears no relation to the bounds of Field. --------- -- Get -- @@ -392,7 +396,7 @@ package body Ada.Text_IO.Fixed_IO is Last : Natural; begin - if Fore - Boolean'Pos (Item < 0.0) < 1 or else Fore > Field'Last then + if Fore - Boolean'Pos (Item < 0.0) < 1 then raise Layout_Error; end if; @@ -407,7 +411,7 @@ package body Ada.Text_IO.Fixed_IO is (To : out String; Last : out Natural; Item : Num; - Fore : Field; + Fore : Integer; Aft : Field; Exp : Field) is