This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
libstdc++/4522: Improperly set eofbit in __copy_streambufs
- To: gcc-gnats at gcc dot gnu dot org
- Subject: libstdc++/4522: Improperly set eofbit in __copy_streambufs
- From: howes at ll dot mit dot edu
- Date: Wed, 10 Oct 2001 11:27:13 -0400 (EDT)
- Reply-To: howes at ll dot mit dot edu
>Number: 4522
>Category: libstdc++
>Synopsis: Improperly set eofbit in __copy_streambufs
>Confidential: no
>Severity: non-critical
>Priority: medium
>Responsible: unassigned
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Wed Oct 10 08:36:00 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator: Brad Howes
>Release: 3.0.1
>Organization:
>Environment:
System: SunOS max 5.8 Generic_108528-07 sun4u sparc SUNW,Sun-Blade-100
Architecture: sun4
host: sparc-sun-solaris2.8
build: sparc-sun-solaris2.8
target: sparc-sun-solaris2.8
configured with: ../gcc-3.0.1/configure
>Description:
The following code raises EOF for cout, which is not correct:
// foo.cc
#include <iostream>
#include <strstream>
int
main(int argc, const char* argv[])
{
const char* data = "first line # comment\n\
second line\n\
# commentary line\n\
last line\n";
std::istrstream iss(data);
std::cout << "Original:" << std::endl << iss.rdbuf();
short state = std::cout.rdstate();
std::cout.clear();
std::cout << "flags: " << std::hex << state << std::endl;
}
>How-To-Repeat:
Compiled using: g++ -g -o foo foo.cc
>Fix:
I've applied the following patches to my streambuf.tcc and istream.tcc, but I'm
not sure about their validity.
*** streambuf.tcc~ Tue Oct 9 08:38:39 2001
--- streambuf.tcc Wed Oct 10 09:41:45 2001
***************
*** 204,221 ****
__xtrct = __sbout->sputn(__sbin->gptr(), __bufsize);
__ret += __xtrct;
__sbin->_M_in_cur_move(__xtrct);
! if (__xtrct == __bufsize)
{
! int_type __c = __sbin->sgetc();
! if (__c == _Traits::eof())
{
- __ios.setstate(ios_base::eofbit);
break;
}
__bufsize = __sbin->in_avail();
}
- else
- break;
}
}
catch(exception& __fail) {
--- 204,218 ----
__xtrct = __sbout->sputn(__sbin->gptr(), __bufsize);
__ret += __xtrct;
__sbin->_M_in_cur_move(__xtrct);
! __bufsize -= __xtrct;
! if (0 == __bufsize)
{
! if (__sbin->sgetc() == _Traits::eof())
{
break;
}
__bufsize = __sbin->in_avail();
}
}
}
catch(exception& __fail) {
*** istream.tcc~ Tue Oct 9 08:38:15 2001
--- istream.tcc Wed Oct 10 09:38:01 2001
***************
*** 458,464 ****
--- 458,467 ----
__streambuf_type* __sbin = this->rdbuf();
sentry __cerb(*this, false);
if (__sbout && __cerb)
+ {
__xtrct = __copy_streambufs(*this, __sbin, __sbout);
+ this->setstate(ios_base::eofbit);
+ }
if (!__sbout || !__xtrct)
this->setstate(ios_base::failbit);
return *this;
>Release-Note:
>Audit-Trail:
>Unformatted: