performance/ifstream_getline.cc goes into endless loop?
Pétur Runólfsson
peturr02@ru.is
Sun Jun 22 11:13:00 GMT 2003
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
More information about the Libstdc++
mailing list