public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [Ada] Fixed I/O to a string
@ 2010-06-21 13:39 Arnaud Charlet
  0 siblings, 0 replies; only message in thread
From: Arnaud Charlet @ 2010-06-21 13:39 UTC (permalink / raw)
  To: gcc-patches; +Cc: Ed Schonberg

[-- Attachment #1: Type: text/plain, Size: 861 bytes --]

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.


[-- Attachment #2: difs --]
[-- Type: text/plain, Size: 1897 bytes --]

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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2010-06-21 13:27 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-06-21 13:39 [Ada] Fixed I/O to a string Arnaud Charlet

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).