🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: gnu.g++.lib.bug
2 messages
2 total messages Started by Jim Nisbet Tue, 17 Nov 1992 23:49
iostream get bug (with example)
#351
Author: Jim Nisbet
Date: Tue, 17 Nov 1992 23:49
74 lines
2994 bytes
re: bug in istream "get" function.

If you do a "get(buf, len, delim)" which happens to return zero
characters because the delim is the very next character then failbit
is incorrectly set.

The problem seems to be in libg++/iostream/igetline.C where it sets
failbit if count <= 0 (this is done in a couple of places).  Does it
make sense to change that to "< 0"?

>From igetline.C ...

istream& istream::getline(char* buf, int len, char delim)
{
    _gcount = 0;
    if (ipfx1()) {
        long count = rdbuf()->sgetline(buf, len, delim, 0);
        _gcount = count;
        if (count <= 0 || count == len-1)  // <--
            set(ios::failbit);
    }
    return *this;
}

------------------------

Example demonstrating inconsistency between AT&T iostream and
libg++2.2.  ...

Script started on Tue Nov 17 15:26:17 1992
Lindy:/main/niz[1]> cat iobug.C
#include <iostream.h>
//  Demonstrates a bug in libg++ 2.2 istream "get" procedure.
main() {
   char buf[100];
   do {
      cin.get(buf, 100, '\n');
      cout << "returns: '" << buf << "'" << endl;
      char ch; cin.get(ch);
   } while (cin.good());
   cout << "eof=" << cin.eof() << ", fail=" << cin.fail() << endl;
}

Lindy:/main/niz[2]> CC iobug.C
Lindy:/main/niz[3]> a.out
null line follows

returns: 'null line follows'
returns: ''
now more lines follow
returns: 'now more lines follow'
end of file is next
returns: 'end of file is next'
^D
returns: 'end of file is next'
eof=1, fail=2
Lindy:/main/niz[4]> g++ -v iobug.C
Reading specs from /usr/local/lib/gcc-lib/sparc-sun-sunos4.1/2.3.1/specs
gcc version 2.3.1
 /usr/local/lib/gcc-lib/sparc-sun-sunos4.1/2.3.1/cpp -lang-c++ -v -undef -D__GNUC__=2 -D__GNUG__=2 -D__cplusplus -Dsparc -Dsun -Dunix -D__sparc__ -D__sun__ -D__unix__ -D__sparc -D__sun -D__unix iobug.C /usr/tmp/cca06172.i
GNU CPP version 2.3.1 (sparc)
 /usr/local/lib/gcc-lib/sparc-sun-sunos4.1/2.3.1/cc1plus /usr/tmp/cca06172.i -quiet -dumpbase iobug.cc -version -o /usr/tmp/cca06172.s
GNU C++ version 2.3.1 (sparc) compiled by GNU C version 2.3.1.
 as -o /usr/tmp/cca061721.o /usr/tmp/cca06172.s
 /usr/local/lib/gcc-lib/sparc-sun-sunos4.1/2.3.1/ld -e start -dc -dp /lib/crt0.o -L/usr/local/lib/gcc-lib/sparc-sun-sunos4.1/2.3.1 -L/usr/local/lib /usr/tmp/cca061721.o -lg++ -lgcc -lc -lgcc
Lindy:/main/niz[5]> a.out
null line follows
returns: 'null line follows'
returns: ''

eof=0, fail=2
^D
Lindy:/main/niz[6]> exit
script done on Tue Nov 17 15:28:19 1992
Re: iostream get bug (with example)
#356
Author: bothner
Date: Tue, 17 Nov 1992 13:32
7 lines
695 bytes
> re: bug in istream "get" function.

I believe this problem will be fixed in 2.3; which should be out
as soon as we get more testing (and fix compiler buglets that
this uncovers).
	--Per Bothner
Cygnus Support     bothner@cygnus.com
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads