This is the mail archive of the
libstdc++@sourceware.cygnus.com
mailing list for the libstdc++ project.
basic_streambuf bug
- To: libstdc++ at sourceware dot cygnus dot com
- Subject: basic_streambuf bug
- From: Vadim Egorov <egorovv at mailandnews dot com>
- Date: 03 May 2000 17:50:28 +0400
- Reply-to: libstdc++ at sourceware dot cygnus dot com
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;
}