g-catiio.ads, [...] (Image): Check for null picture string

2007-04-20  Robert Dewar  <dewar@adacore.com>

	* g-catiio.ads, g-catiio.adb (Image): Check for null picture string

From-SVN: r125413
This commit is contained in:
Robert Dewar 2007-06-06 12:28:45 +02:00 committed by Arnaud Charlet
parent a2fd0ecb6e
commit f24f72e892
2 changed files with 28 additions and 11 deletions

View File

@ -6,7 +6,7 @@
-- -- -- --
-- B o d y -- -- B o d y --
-- -- -- --
-- Copyright (C) 1999-2006, AdaCore -- -- Copyright (C) 1999-2007, AdaCore --
-- -- -- --
-- 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- --
@ -202,19 +202,32 @@ package body GNAT.Calendar.Time_IO is
Second : Second_Number; Second : Second_Number;
Sub_Second : Second_Duration; Sub_Second : Second_Duration;
P : Positive := Picture'First; P : Positive;
begin begin
-- Get current time in split format
Split (Date, Year, Month, Day, Hour, Minute, Second, Sub_Second); Split (Date, Year, Month, Day, Hour, Minute, Second, Sub_Second);
loop -- Null picture string is error
if Picture = "" then
raise Picture_Error with "null picture string";
end if;
-- Loop through characters of picture string, building result
Result := Null_Unbounded_String;
P := Picture'First;
while P <= Picture'Last loop
-- A directive has the following format "%[-_]." -- A directive has the following format "%[-_]."
if Picture (P) = '%' then if Picture (P) = '%' then
Padding := Zero; Padding := Zero;
if P = Picture'Last then if P = Picture'Last then
raise Picture_Error; raise Picture_Error with "picture string ends with '%";
end if; end if;
-- Check for GNU extension to change the padding -- Check for GNU extension to change the padding
@ -222,13 +235,14 @@ package body GNAT.Calendar.Time_IO is
if Picture (P + 1) = '-' then if Picture (P + 1) = '-' then
Padding := None; Padding := None;
P := P + 1; P := P + 1;
elsif Picture (P + 1) = '_' then elsif Picture (P + 1) = '_' then
Padding := Space; Padding := Space;
P := P + 1; P := P + 1;
end if; end if;
if P = Picture'Last then if P = Picture'Last then
raise Picture_Error; raise Picture_Error with "picture string ends with '- or '_";
end if; end if;
case Picture (P + 1) is case Picture (P + 1) is
@ -462,18 +476,21 @@ package body GNAT.Calendar.Time_IO is
Result := Result & Image (Year, None, 4); Result := Result & Image (Year, None, 4);
when others => when others =>
raise Picture_Error; raise Picture_Error with
"unknown format character in picture string";
end case; end case;
-- Skip past % and format character
P := P + 2; P := P + 2;
-- Character other than % is copied into the result
else else
Result := Result & Picture (P); Result := Result & Picture (P);
P := P + 1; P := P + 1;
end if; end if;
exit when P > Picture'Last;
end loop; end loop;
return To_String (Result); return To_String (Result);

View File

@ -6,7 +6,7 @@
-- -- -- --
-- S p e c -- -- S p e c --
-- -- -- --
-- Copyright (C) 1999-2006, AdaCore -- -- Copyright (C) 1999-2007, AdaCore --
-- -- -- --
-- 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- --
@ -114,7 +114,7 @@ package GNAT.Calendar.Time_IO is
(Date : Ada.Calendar.Time; (Date : Ada.Calendar.Time;
Picture : Picture_String) return String; Picture : Picture_String) return String;
-- Return Date as a string with format Picture. Raise Picture_Error if -- Return Date as a string with format Picture. Raise Picture_Error if
-- picture string is wrong. -- picture string is null or has an incorrect format.
function Value (Date : String) return Ada.Calendar.Time; function Value (Date : String) return Ada.Calendar.Time;
-- Parse the string Date and return its equivalent as a Time value. The -- Parse the string Date and return its equivalent as a Time value. The