basic_streambuf bug

Vadim Egorov egorovv@mailandnews.com
Wed May 3 06:50:00 GMT 2000


Hello,

There seemes to be a bug in basic_streambuf::xsgetn.
This simple test demonstrates it:

[test]# cat streamtest.cc
#include <iostream>
#include <fstream>

using namespace std;

int main()
{
    ifstream ifs("streamtest.txt");
    char buffer[] = "xxxxxxxxxx";
    size_t len = ifs.rdbuf()->sgetn(buffer, sizeof (buffer));
    cout.rdbuf()->sputn(buffer, len);
}
[test]# cat streamtest.txt
0123456789[test]# ./streamtest
123456789x[test]# 

The following patch fixes the problem.

-- 
Regards,
Vadim Egorov 

2000-05-03  Vadim Egorov  <egorovv@mailandnews.com>

	* bits/streambuf.tcc (basic_streambuf::xsgetn): Fix uflow case

Index: streambuf.tcc
===================================================================
RCS file: /cvs/libstdc++/libstdc++/bits/streambuf.tcc,v
retrieving revision 1.29
diff -c -r1.29 streambuf.tcc
*** streambuf.tcc	2000/03/21 06:24:04	1.29
--- streambuf.tcc	2000/05/03 12:14:34
***************
*** 146,153 ****
  	      
  	      if (__retval != __n)
  		{
! 		  if (this->uflow() != traits_type::eof())
! 		    ++__retval;
  		  else
  		    break;
  		}
--- 146,157 ----
  	      
  	      if (__retval != __n)
  		{
! 		  int_type __c = this->uflow();  
! 		  if ( __c != traits_type::eof())
! 		    {
! 		      *__s++ = __c;
! 		      ++__retval;
! 		    }
  		  else
  		    break;
  		}



More information about the Libstdc++ mailing list