From: "Jeffrey R. Carter" <spam.jrcarter.not@spam.not.acm.org>
Subject: Re: Ada.Text_IO.Get_Line issue in windows
Date: Tue, 02 Jun 2015 23:32:02 -0700
Date: 2015-06-02T23:32:02-07:00 [thread overview]
Message-ID: <mkm6up$2u7$1@dont-email.me> (raw)
In-Reply-To: <556e96a4$0$11114$c3e8da3@news.astraweb.com>
On 06/02/2015 10:54 PM, tornenvi wrote:
>
> I believe I have found the problem in that file (a-tigeli.adb)
>
> I believe line 193 which is
>
> elsif ch /= LM then
>
> should read
>
> elsif ch /= LM and ch /=EOF then
In context, this is
ch := Getc (File);
-- If we get EOF after already reading data, this is an incomplete
-- last line, in which case no End_Error should be raised.
if ch = EOF and then Last < Item'First then
raise End_Error;
elsif ch /= LM then
-- Buffer really is full without having seen LM, update col
Last := Last + 1;
Item (Last) := Character'Val (ch);
File.Col := File.Col + Count (Last - Item'First + 1);
return;
end if;
We can see that if EOF is encountered after reading characters into Item then
the EOF is incorrectly stored in Item, so you have found an error in Get_Line.
While your change will work, it might be better to rewrite the "if" as
if ch = EOF then
if Last < Item'First then
raise End_Error;
end if;
elsif ch = LM then
null;
else -- ch /= EOF and ch /= LM
...
end if;
to divide the code into the 3 cases of interest: EOF, in which case we either
raise End_Error or do nothing, depending on Last; LM, do nothing; and anything
else, store the character in Item.
It's disturbing that EOF can be converted into a valid Character.
--
Jeff Carter
"Frankie Wolf, wanted by Federal authorities for
dancing with a mailman."
Take the Money and Run
143
next prev parent reply other threads:[~2015-06-03 6:32 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-06-01 5:07 Ada.Text_IO.Get_Line issue in windows tornenvi
2015-06-02 2:44 ` AdaMagica
2015-06-03 5:54 ` tornenvi
2015-06-03 6:32 ` Jeffrey R. Carter [this message]
2015-06-05 4:10 ` tornenvi
2015-06-03 7:02 ` Simon Wright
2015-06-03 10:08 ` Simon Clubley
2015-06-03 11:14 ` Simon Wright
2015-06-08 22:47 ` wowwomenonwheels205
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox