home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / gnu / g / lib / bug / 598 < prev    next >
Encoding:
Text File  |  1992-11-17  |  2.8 KB  |  89 lines

  1. Newsgroups: gnu.g++.lib.bug
  2. Path: sparky!uunet!usc!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!jessica.stanford.edu!niz
  3. From: niz@jessica.stanford.edu (Jim Nisbet)
  4. Subject: iostream get bug (with example)
  5. Message-ID: <1992Nov17.234901.5841@leland.Stanford.EDU>
  6. Sender: gnulists@ai.mit.edu
  7. Reply-To: niz@jessica.stanford.edu (Jim Nisbet)
  8. Organization: Stanford University
  9. Distribution: gnu
  10. Date: Tue, 17 Nov 1992 23:49:01 GMT
  11. Approved: bug-lib-g++@prep.ai.mit.edu
  12. Lines: 75
  13.  
  14. re: bug in istream "get" function.
  15.  
  16. If you do a "get(buf, len, delim)" which happens to return zero
  17. characters because the delim is the very next character then failbit
  18. is incorrectly set.
  19.  
  20. The problem seems to be in libg++/iostream/igetline.C where it sets
  21. failbit if count <= 0 (this is done in a couple of places).  Does it
  22. make sense to change that to "< 0"?
  23.  
  24. >From igetline.C ...
  25.  
  26. istream& istream::getline(char* buf, int len, char delim)
  27. {
  28.     _gcount = 0;
  29.     if (ipfx1()) {
  30.         long count = rdbuf()->sgetline(buf, len, delim, 0);
  31.         _gcount = count;
  32.         if (count <= 0 || count == len-1)  // <--
  33.             set(ios::failbit);
  34.     }
  35.     return *this;
  36. }
  37.  
  38. ------------------------
  39.  
  40. Example demonstrating inconsistency between AT&T iostream and
  41. libg++2.2.  ...
  42.  
  43. Script started on Tue Nov 17 15:26:17 1992
  44. Lindy:/main/niz[1]> cat iobug.C
  45. #include <iostream.h>
  46. //  Demonstrates a bug in libg++ 2.2 istream "get" procedure.
  47. main() {
  48.    char buf[100];
  49.    do {
  50.       cin.get(buf, 100, '\n');
  51.       cout << "returns: '" << buf << "'" << endl;
  52.       char ch; cin.get(ch);
  53.    } while (cin.good());
  54.    cout << "eof=" << cin.eof() << ", fail=" << cin.fail() << endl;
  55. }
  56.  
  57. Lindy:/main/niz[2]> CC iobug.C
  58. Lindy:/main/niz[3]> a.out
  59. null line follows
  60.  
  61. returns: 'null line follows'
  62. returns: ''
  63. now more lines follow
  64. returns: 'now more lines follow'
  65. end of file is next
  66. returns: 'end of file is next'
  67. ^D
  68. returns: 'end of file is next'
  69. eof=1, fail=2
  70. Lindy:/main/niz[4]> g++ -v iobug.C
  71. Reading specs from /usr/local/lib/gcc-lib/sparc-sun-sunos4.1/2.3.1/specs
  72. gcc version 2.3.1
  73.  /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
  74. GNU CPP version 2.3.1 (sparc)
  75.  /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
  76. GNU C++ version 2.3.1 (sparc) compiled by GNU C version 2.3.1.
  77.  as -o /usr/tmp/cca061721.o /usr/tmp/cca06172.s
  78.  /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
  79. Lindy:/main/niz[5]> a.out
  80. null line follows
  81. returns: 'null line follows'
  82. returns: ''
  83.  
  84. eof=0, fail=2
  85. ^D
  86. Lindy:/main/niz[6]> exit
  87. script done on Tue Nov 17 15:28:19 1992
  88.  
  89.