Patchwork [Ada] Fixed I/O to a string

login
register
mail settings
Submitter Arnaud Charlet
Date June 21, 2010, 1:27 p.m.
Message ID <20100621132704.GA20235@adacore.com>
Download mbox | patch
Permalink /patch/56313/
State New
Headers show

Comments

Arnaud Charlet - June 21, 2010, 1:27 p.m.
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  <schonberg@adacore.com>

	* 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.

Patch

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