From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!feeder.eternal-september.org!border1.nntp.ams1.giganews.com!nntp.giganews.com!news.astraweb.com!border5.a.newsrouter.astraweb.com!not-for-mail Date: Fri, 05 Jun 2015 13:40:26 +0930 From: tornenvi User-Agent: Mozilla/5.0 (Windows NT 6.2; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Ada.Text_IO.Get_Line issue in windows References: <556be876$0$2775$c3e8da3$76491128@news.astraweb.com> <4c705bb2-6bf8-4ff2-a3a8-651a5ba204fa@googlegroups.com> <556e96a4$0$11114$c3e8da3@news.astraweb.com> In-Reply-To: Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Message-ID: <55712134$0$12900$c3e8da3$5496439d@news.astraweb.com> Organization: Unlimited download news at news.astraweb.com NNTP-Posting-Host: bc595e34.news.astraweb.com X-Trace: DXC=lOQG4I\ZRF:fB5aLm@JgRV^?kW357CfU0a:[?A8?9jXgR?N0 Xref: news.eternal-september.org comp.lang.ada:26187 Date: 2015-06-05T13:40:26+09:30 List-Id: On 6/3/2015 4:02 PM, Jeffrey R. Carter wrote: > 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. > I have already reported the bug on bugzilla, the link to it is below. https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66390 You can add your suggested change to the bug report, or I can update it if you like. However I'm not set up to report patch files (tested) so I am only adding the changes as comments to the bug report. Also note that line 84 of \gcc\ada\a-tigeli.adb reads memset (S, 10, size_t (N)); I believe the hardcoded '10' here should be 'LM'. I have added it as a comment to the bug report.