Commit fd013778 by Geert Bosch Committed by Arnaud Charlet

re PR ada/20753 (ACATS ce3810b segfaults at runtime)

2006-02-13  Geert Bosch  <bosch@adacore.com>
	    Gary Dismukes  <dismukes@adacore.com>

	* a-tifiio.adb (Put_Digits): Test Last against To'First - 1 instead of
	0, since the lower bound of the actual string may be greater than one.

	PR ada/20753

	(Put): Fix condition to raise Layout_Error when invalid
	layout is requested.

From-SVN: r111043
parent 531eb217
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
-- -- -- --
-- B o d y -- -- B o d y --
-- -- -- --
-- Copyright (C) 1992-2005, Free Software Foundation, Inc. -- -- Copyright (C) 1992-2006, Free Software Foundation, Inc. --
-- -- -- --
-- GNAT is free software; you can redistribute it and/or modify it under -- -- 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- -- -- terms of the GNU General Public License as published by the Free Soft- --
...@@ -314,9 +314,9 @@ package body Ada.Text_IO.Fixed_IO is ...@@ -314,9 +314,9 @@ package body Ada.Text_IO.Fixed_IO is
--------- ---------
procedure Get procedure Get
(File : in File_Type; (File : File_Type;
Item : out Num; Item : out Num;
Width : in Field := 0) Width : Field := 0)
is is
pragma Unsuppress (Range_Check); pragma Unsuppress (Range_Check);
...@@ -329,7 +329,7 @@ package body Ada.Text_IO.Fixed_IO is ...@@ -329,7 +329,7 @@ package body Ada.Text_IO.Fixed_IO is
procedure Get procedure Get
(Item : out Num; (Item : out Num;
Width : in Field := 0) Width : Field := 0)
is is
pragma Unsuppress (Range_Check); pragma Unsuppress (Range_Check);
...@@ -341,7 +341,7 @@ package body Ada.Text_IO.Fixed_IO is ...@@ -341,7 +341,7 @@ package body Ada.Text_IO.Fixed_IO is
end Get; end Get;
procedure Get procedure Get
(From : in String; (From : String;
Item : out Num; Item : out Num;
Last : out Positive) Last : out Positive)
is is
...@@ -359,11 +359,11 @@ package body Ada.Text_IO.Fixed_IO is ...@@ -359,11 +359,11 @@ package body Ada.Text_IO.Fixed_IO is
--------- ---------
procedure Put procedure Put
(File : in File_Type; (File : File_Type;
Item : in Num; Item : Num;
Fore : in Field := Default_Fore; Fore : Field := Default_Fore;
Aft : in Field := Default_Aft; Aft : Field := Default_Aft;
Exp : in Field := Default_Exp) Exp : Field := Default_Exp)
is is
S : String (1 .. Fore + Aft + Exp + Extra_Layout_Space); S : String (1 .. Fore + Aft + Exp + Extra_Layout_Space);
Last : Natural; Last : Natural;
...@@ -373,10 +373,10 @@ package body Ada.Text_IO.Fixed_IO is ...@@ -373,10 +373,10 @@ package body Ada.Text_IO.Fixed_IO is
end Put; end Put;
procedure Put procedure Put
(Item : in Num; (Item : Num;
Fore : in Field := Default_Fore; Fore : Field := Default_Fore;
Aft : in Field := Default_Aft; Aft : Field := Default_Aft;
Exp : in Field := Default_Exp) Exp : Field := Default_Exp)
is is
S : String (1 .. Fore + Aft + Exp + Extra_Layout_Space); S : String (1 .. Fore + Aft + Exp + Extra_Layout_Space);
Last : Natural; Last : Natural;
...@@ -387,9 +387,9 @@ package body Ada.Text_IO.Fixed_IO is ...@@ -387,9 +387,9 @@ package body Ada.Text_IO.Fixed_IO is
procedure Put procedure Put
(To : out String; (To : out String;
Item : in Num; Item : Num;
Aft : in Field := Default_Aft; Aft : Field := Default_Aft;
Exp : in Field := Default_Exp) Exp : Field := Default_Exp)
is is
Fore : constant Integer := To'Length Fore : constant Integer := To'Length
- 1 -- Decimal point - 1 -- Decimal point
...@@ -399,7 +399,7 @@ package body Ada.Text_IO.Fixed_IO is ...@@ -399,7 +399,7 @@ package body Ada.Text_IO.Fixed_IO is
Last : Natural; Last : Natural;
begin begin
if Fore not in Field'Range then if Fore < 1 or else Fore > Field'Last then
raise Layout_Error; raise Layout_Error;
end if; end if;
...@@ -419,6 +419,7 @@ package body Ada.Text_IO.Fixed_IO is ...@@ -419,6 +419,7 @@ package body Ada.Text_IO.Fixed_IO is
Exp : Field) Exp : Field)
is is
subtype Digit is Int64 range 0 .. 9; subtype Digit is Int64 range 0 .. 9;
X : constant Int64 := Int64'Integer_Value (Item); X : constant Int64 := Int64'Integer_Value (Item);
A : constant Field := Field'Max (Aft, 1); A : constant Field := Field'Max (Aft, 1);
Neg : constant Boolean := (Item < 0.0); Neg : constant Boolean := (Item < 0.0);
...@@ -438,7 +439,7 @@ package body Ada.Text_IO.Fixed_IO is ...@@ -438,7 +439,7 @@ package body Ada.Text_IO.Fixed_IO is
procedure Put_Digit (X : Digit); procedure Put_Digit (X : Digit);
-- Add digit X to the output string (going from left to right), -- Add digit X to the output string (going from left to right),
-- updating Last and Pos, and inserting the sign, leading zeroes -- updating Last and Pos, and inserting the sign, leading zeros
-- or a decimal point when necessary. After outputting the first -- or a decimal point when necessary. After outputting the first
-- digit, Pos must not be changed outside Put_Digit anymore -- digit, Pos must not be changed outside Put_Digit anymore
...@@ -470,11 +471,12 @@ package body Ada.Text_IO.Fixed_IO is ...@@ -470,11 +471,12 @@ package body Ada.Text_IO.Fixed_IO is
procedure Put_Digit (X : Digit) is procedure Put_Digit (X : Digit) is
Digs : constant array (Digit) of Character := "0123456789"; Digs : constant array (Digit) of Character := "0123456789";
begin begin
if Last = 0 then if Last = To'First - 1 then
if X /= 0 or Pos <= 0 then if X /= 0 or Pos <= 0 then
-- Before outputting first digit, include leading space, -- Before outputting first digit, include leading space,
-- posible minus sign and, if the first digit is fractional, -- possible minus sign and, if the first digit is fractional,
-- decimal seperator and leading zeros. -- decimal seperator and leading zeros.
-- The Fore part has Pos + 1 + Boolean'Pos (Neg) characters, -- The Fore part has Pos + 1 + Boolean'Pos (Neg) characters,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment