public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* Re: libstdc++/4419: ifstream::get(buffer,len) stops reading when an empty line appears.
@ 2002-03-11 13:35 pme
  0 siblings, 0 replies; 5+ messages in thread
From: pme @ 2002-03-11 13:35 UTC (permalink / raw)
  To: gcc-bugs, gcc-prs, paolo, pavenis, salvador

Synopsis: ifstream::get(buffer,len) stops reading when an empty line appears.

State-Changed-From-To: feedback->closed
State-Changed-By: pme
State-Changed-When: Mon Mar 11 13:35:41 2002
State-Changed-Why:
    The bug is in the user's code.  The standard specifies that if no characters are extracted -- which is the case when calling get() on an empty line -- then the stream's failbit is set.  The code should is not testing for failbit.
    
    Here is a modified testcase:
    
    
    #include <fstream>
    
    const int maxLineLength=200;
    
    int main(void)
    {
     std::ifstream fileToView("4419.data");
     char line[maxLineLength+1];
     int len=0;
     //while(!fileToView.eof())
     while(fileToView)
       {
        fileToView.get(line, sizeof line);
        char c;
        fileToView.get(c);      // grab trailing newline
        printf("%d (%d)\n",strlen(line),c);
        // Sanity stop
        if (++len==20) return 1;
       }
     printf("EOF: %d\n",fileToView.eof());
     printf("goodbit: %d\n",fileToView.good());
     printf("failbit: %d\n",fileToView.fail());
     printf("badbit: %d\n",fileToView.bad());
     return 0;
    }
    
    Note the change in the while condition.  Output is:
    
    10 (10)
    12 (10)
    0 (10)
    EOF: 0
    goodbit: 0
    failbit: 1
    badbit: 0
    
    So the condition is being indicated, but the user was only
    testing for EOF, not for a general "stop" condition.

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=4419


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: libstdc++/4419: ifstream::get(buffer,len) stops reading when an  empty line appears.
@ 2001-12-10  4:46 salvador
  0 siblings, 0 replies; 5+ messages in thread
From: salvador @ 2001-12-10  4:46 UTC (permalink / raw)
  To: paolo; +Cc: gcc-prs

The following reply was made to PR libstdc++/4419; it has been noted by GNATS.

From: salvador <salvador@inti.gov.ar>
To: paolo@gcc.gnu.org
Cc: gcc-bugs@gcc.gnu.org, gcc-gnats@gcc.gnu.org,
 	gcc-prs@gcc.gnu.org, nobody@gcc.gnu.org,  pavenis@lanet.lv
Subject: Re: libstdc++/4419: ifstream::get(buffer,len) stops reading when an 
 empty line appears.
Date: Mon, 10 Dec 2001 09:44:05 -0300

 paolo@gcc.gnu.org wrote:
 
 > Synopsis: ifstream::get(buffer,len) stops reading when an empty line appears.
 >
 > Responsible-Changed-From-To: unassigned->paolo
 > Responsible-Changed-By: paolo
 > Responsible-Changed-When: Sat Dec  8 02:42:46 2001
 > Responsible-Changed-Why:
 >     Looking into it.
 > State-Changed-From-To: open->feedback
 > State-Changed-By: paolo
 > State-Changed-When: Sat Dec  8 02:42:46 2001
 > State-Changed-Why:
 >     Why don't you use something like:
 >
 >       while(!fileToView.eof())
 >         {
 >           fileToView.getline(line, sizeof line);
 >           printf("%d\n",strlen(line));
 >         }
 >
 >     ???
 
 That's more or less what I'm doing now. But the problem is that I was porting all
 code that used the other way and was working for years.
 As this code is an example of a library I'm affraid a lot of people will be using the
 old approach and failing.
 I got really confused when the code break without any apparent reason.
 
 SET
 
 BTW: What I use now is a macro, it expands to getline for gcc (libstdc++ v2 and v3)
 but I was forced to expand it to a function call for Borland compilers where the
 getline fails to extract the trailing newline.
 
 --
 Salvador Eduardo Tropea (SET). (Electronics Engineer)
 Visit my home page: http://welcome.to/SetSoft or
 http://www.geocities.com/SiliconValley/Vista/6552/
 Alternative e-mail: set@computer.org set@ieee.org
 Address: Curapaligue 2124, Caseros, 3 de Febrero
 Buenos Aires, (1678), ARGENTINA Phone: +(5411) 4759 0013
 
 
 


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: libstdc++/4419: ifstream::get(buffer,len) stops reading when an empty line appears.
@ 2001-12-08  2:46 paolo
  0 siblings, 0 replies; 5+ messages in thread
From: paolo @ 2001-12-08  2:46 UTC (permalink / raw)
  To: paolo; +Cc: gcc-prs

The following reply was made to PR libstdc++/4419; it has been noted by GNATS.

From: paolo@gcc.gnu.org
To: gcc-bugs@gcc.gnu.org, gcc-gnats@gcc.gnu.org, gcc-prs@gcc.gnu.org,
  nobody@gcc.gnu.org, paolo@gcc.gnu.org, pavenis@lanet.lv,
  salvador@inti.gov.ar
Cc:  
Subject: Re: libstdc++/4419: ifstream::get(buffer,len) stops reading when an empty line appears.
Date: 8 Dec 2001 10:42:47 -0000

 Synopsis: ifstream::get(buffer,len) stops reading when an empty line appears.
 
 Responsible-Changed-From-To: unassigned->paolo
 Responsible-Changed-By: paolo
 Responsible-Changed-When: Sat Dec  8 02:42:46 2001
 Responsible-Changed-Why:
     Looking into it.
 State-Changed-From-To: open->feedback
 State-Changed-By: paolo
 State-Changed-When: Sat Dec  8 02:42:46 2001
 State-Changed-Why:
     Why don't you use something like:
     
       while(!fileToView.eof())
         {
           fileToView.getline(line, sizeof line);
           printf("%d\n",strlen(line)); 
         }
     
     ???
 
 http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&pr=4419&database=gcc


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: libstdc++/4419: ifstream::get(buffer,len) stops reading when an empty line appears.
@ 2001-12-08  2:42 paolo
  0 siblings, 0 replies; 5+ messages in thread
From: paolo @ 2001-12-08  2:42 UTC (permalink / raw)
  To: gcc-bugs, gcc-gnats, gcc-prs, nobody, paolo, pavenis, salvador

Synopsis: ifstream::get(buffer,len) stops reading when an empty line appears.

Responsible-Changed-From-To: unassigned->paolo
Responsible-Changed-By: paolo
Responsible-Changed-When: Sat Dec  8 02:42:46 2001
Responsible-Changed-Why:
    Looking into it.
State-Changed-From-To: open->feedback
State-Changed-By: paolo
State-Changed-When: Sat Dec  8 02:42:46 2001
State-Changed-Why:
    Why don't you use something like:
    
      while(!fileToView.eof())
        {
          fileToView.getline(line, sizeof line);
          printf("%d\n",strlen(line)); 
        }
    
    ???

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&pr=4419&database=gcc


^ permalink raw reply	[flat|nested] 5+ messages in thread

* libstdc++/4419: ifstream::get(buffer,len) stops reading when an empty line appears.
@ 2001-09-28 15:06 salvador
  0 siblings, 0 replies; 5+ messages in thread
From: salvador @ 2001-09-28 15:06 UTC (permalink / raw)
  To: gcc-gnats; +Cc: pavenis

>Number:         4419
>Category:       libstdc++
>Synopsis:       ifstream::get(buffer,len) stops reading when an empty line appears.
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Fri Sep 28 15:06:01 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator:     libstdc++ streams
>Release:        libstdc++-3.x
>Organization:
>Environment:
i586-pc-msdosdjgpp      gcc-3.0.1 release
i586-pc-msdosdjgpp      gcc-3.1 20010927 (experimental)
i686-pc-linux-gnu       gcc-3.0.2 20010927 (prerelease)
>Description:
When reading a text file from an input stream using the get 
member you can't read all the file if it contains an empty
line (one with \n).
The stream stops reading lines at rhis point.
Here is the complete explanation I reported by mail:
Hi All!

  GCC 3.0 changed too much things in the C++ classes to follow the new
standard (is that ISO C++ 1998?).
  I was "fighting" to support it in the TV library. Thanks to Andris and
other
people I got the library compiled. But while testing the examples I found
a really strange behavior.
  I don't know if that is a bug and in this case if that's djgpp specific.
So I need help from somebody with:

a) Access to another systems with gcc 3.x (not djgpp)
b) Knowledge about the new streams.

  It looks like a bug and as it is for lines that only contains EOL (\r\n)
could
be related to djgpp's \r\n to \n traslation. The following code compiled
with
gcc 2.95.x can read a complete file name meassuring the length of each
line. The same code compiled with 3.0.1 will stop reading in the first empty

line and from this point will enter in an endless loop. Note that EOF is not

reached nor indicated with gcc 3.

Here is the stripped code (the original loads the text in memory):

#include <fstream.h>

const int maxLineLength=200;

int main(void)
{
 ifstream fileToView("test.txt");
 char line[maxLineLength+1];
 int len=0;
 while(!fileToView.eof())
   {
    fileToView.get(line, sizeof line);
    char c;
    fileToView.get(c);      // grab trailing newline
    printf("%d (%d)\n",strlen(line),c);
    // Sanity stop
    if (++len==20) return 1;
   }
 printf("EOF: %d\n",fileToView.eof());
 return 0;
}

Here is what you can use for `test.txt' to feed the example:

<--------
First Line
Another Line

The above is empty

<---------

Output from gcc 2.95.x compiled code:

10 (10)
12 (10)
0 (10)
18 (10)
0 (10)
EOF: 1

Output from gcc 3.0.1 compiled code:

10 (10)
12 (10)
0 (10)
0 (10)
....

SET

>How-To-Repeat:
#include <fstream.h>

const int maxLineLength=200;

int main(void)
{
 ifstream fileToView("test.txt");
 char line[maxLineLength+1];
 int len=0;
 while(!fileToView.eof())
   {
    fileToView.get(line, sizeof line);
    char c;
    fileToView.get(c);      // grab trailing newline
    printf("%d (%d)\n",strlen(line),c);
    // Sanity stop
    if (++len==20) return 1;
   }
 printf("EOF: %d\n",fileToView.eof());
 return 0;
}

/*
Use it to feed the program (test.txt):

<--------
First Line
Another Line

The above is empty

<---------
*/
>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2002-03-11 21:35 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-03-11 13:35 libstdc++/4419: ifstream::get(buffer,len) stops reading when an empty line appears pme
  -- strict thread matches above, loose matches on Subject: below --
2001-12-10  4:46 salvador
2001-12-08  2:46 paolo
2001-12-08  2:42 paolo
2001-09-28 15:06 salvador

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).