This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ 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]

RE: performance/ifstream_getline.cc goes into endless loop?


Andreas Jaeger wrote:
> can one of you libstdc++ experts look whether we have a
> real bug in the library here?

The bug is in the testcase:

  ifstream in(name);
  char buffer[BUFSIZ];
  while(!in.eof()) 
    in.getline(buffer, BUFSIZ);

Note that the loop runs until in.eof() == true (that is, eofbit
is set in in.rdstate(). However, if input fails for any reason
other than reaching the end of the file (say, if the file <name>
doesn't exist), failbit or badbit is set in rdstate(). This causes
all calls to in.getline() to fail without attempting to read
anything, which means that eofbit never gets set.

The testcase should probably be fixed so that the loop stops as
soon as a read fails (that is, in.fail() is true) and if in.eof()
is false at the end of the loop, a warning is given.

Regards,
Petur


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