This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Ada] Fix bug in Text_IO.Set_Col


Tested on i686-linux, committed on mainline.

This patch fixes some problems in Text_IO.Set_Col that have been
present in GNAT forever (few people use Set_Col for input, since
it's a bit odd to simply ignore input). The first error happens
if we are logically positioned before a line mark, and physically
after it (Before_LM set True). In this case, Set_Col must check
for this, otherwise it ends up setting the wrong position. This
happens for example after reading a float value at the end of
the line. The second bug, noticed while working on the first,
is that if we are physically and logically positioned just
before a line mark, and we do a Set_Col for the current position
then it does nothing. That's wrong, Set_Col should always leave
us set to a real character, not a terminator.

The first test program is for the first case, before the patch
it raises Data_Error, after the patch it executes silently.

with TEXT_IO; use TEXT_IO;
procedure T2 is

   package Integer_Io is new Text_Io.Integer_Io (Integer);
   package Float_Io   is new Text_IO.Float_Io (Float);

   D  : Integer := 0;
   CF : TEXT_IO.FILE_TYPE;
   NL : Integer := 0;

   F  : Float;
begin
   CREATE (FILE => CF, MODE => OUT_FILE, NAME => "df.txt");
   Put_Line (CF, "#040     1");
   Put_Line (CF, "20.0");
   Put_Line (CF, "#010     1");
   Put_Line (CF, "10.0");
   CLOSE (CF);

   OPEN (FILE => CF, MODE => IN_FILE, NAME => "df.txt");

   while (not END_OF_FILE (CF)) loop
      Set_Col (CF, 2);
      INTEGER_IO.GET  (FILE => CF, ITEM => D);
      INTEGER_IO.GET  (FILE => CF, ITEM => NL);
      FLOAT_IO.GET    (FILE => CF, ITEM => F);
   end loop;
end T2;

The second test program is for the second case

with TEXT_IO; use TEXT_IO;
procedure T3 is

   package Integer_Io is new Text_Io.Integer_Io (Integer);
   package Float_Io   is new Text_IO.Float_Io (Float);

   D  : Integer := 0;
   CF : TEXT_IO.FILE_TYPE;
   NL : Integer := 0;
   CH : Character;

begin
   CREATE (FILE => CF, MODE => OUT_FILE, NAME => "df.txt");
   Put_Line (CF, "#040     1");
   Put_Line (CF, "20.0     xy");
   CLOSE (CF);

   OPEN (FILE => CF, MODE => IN_FILE, NAME => "df.txt");

   Set_Col (CF, 2);
   INTEGER_IO.GET  (FILE => CF, ITEM => D);
   INTEGER_IO.GET  (FILE => CF, ITEM => NL);
   Set_Col (CF, 11);
   Get (CF, CH);
   Put_Line ("should get y, got -> " & CH);
end T3;

After the patch, this prints

should get y, got -> y

Before the patch, it printed

should get y, got -> 2

2005-06-14  Robert Dewar  <dewar@adacore.com>

	* a-textio.adb (Set_Col): Fix two errors noticed recently, having to
	do with treatment of Set_Col when positioned at end of line character.

Attachment: difs.14
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]