home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: gnu.g++.lib.bug
- Path: sparky!uunet!usc!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!jessica.stanford.edu!niz
- From: niz@jessica.stanford.edu (Jim Nisbet)
- Subject: iostream get bug (with example)
- Message-ID: <1992Nov17.234901.5841@leland.Stanford.EDU>
- Sender: gnulists@ai.mit.edu
- Reply-To: niz@jessica.stanford.edu (Jim Nisbet)
- Organization: Stanford University
- Distribution: gnu
- Date: Tue, 17 Nov 1992 23:49:01 GMT
- Approved: bug-lib-g++@prep.ai.mit.edu
- Lines: 75
-
- 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
-
-