This is the mail archive of the 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]

[bug] istream::getline(char*,streamsize) still broken

ifstream::getline(char*,streamsize) still has bugs -> IMO. I believe
the following testcase should enforce more of the behavior described 
in (17).

#include <cstring>
#include <istream>
#include <sstream>

  const std::streamsize it = 5;
  char tmp[it];
  const char* exact_size = "abcd\n";

  std::stringbuf esb(exact_size, std::ios_base::in);
  std::istream eifs(&esb);
  assert( eifs.getline(tmp,it) ); // failbit not set
  assert( eifs.gcount() == it );  // extracted whole string
  assert( strlen(tmp) == 4 );     // stored all but '\n'
  assert( !eifs.eof() );          // extracted up to but not eof
  return 0;

(the patch in message 
 fixes this. I believe it also causes the desired effect described
 in the 'smoke-filled' committee room comment -r1.2, even w/o an
 explicit n==1 check, since a char is extracted prior to the while, 
 which is not entered for n==1, then putback() if eof or delim was 
 not read [in any case])

Please take a look at this existing patch. if it does not do what is 
desired in the n==1 case, let me know, and I'll make the necessary 


Damon Brent Verner                        o      _     _         _
Cracker Jack? Surprise Certified  _o     /\_   _ \\o  (_)\__/o  (_)                _< \_   _>(_) (_)/<_    \_| \   _|/' \/               (_)>(_) (_)        (_)   (_)    (_)'  _\o_

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