[Bug libstdc++/91653] New: ostream::operator<<(streambuf*) should fail the ostream when write output stream error but not

yhliang86 at hotmail dot com gcc-bugzilla@gcc.gnu.org
Wed Sep 4 02:33:00 GMT 2019


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91653

            Bug ID: 91653
           Summary: ostream::operator<<(streambuf*) should fail the
                    ostream when write output stream error but not
           Product: gcc
           Version: 4.9.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: yhliang86 at hotmail dot com
  Target Milestone: ---

bits/ostream.tcc
 operator<<(__streambuf_type* __sbin):
       if (!__copy_streambufs(__sbin, this->rdbuf()))
        __err |= ios_base::failbit;

expect __copy_streambufs return zero on failure, but __copy_streambufs actually
return copied number, and will never be zero if sputc error after have written
some:

bits/streambuf.tcc
 __copy_streambufs_eof(basic_streambuf<_CharT, _Traits>* __sbin,
              basic_streambuf<_CharT, _Traits>* __sbout,
              bool& __ineof)
    {
      streamsize __ret = 0;
      __ineof = true;
      typename _Traits::int_type __c = __sbin->sgetc();
      while (!_Traits::eq_int_type(__c, _Traits::eof()))
    {
      __c = __sbout->sputc(_Traits::to_char_type(__c));
      if (_Traits::eq_int_type(__c, _Traits::eof()))
        {
          __ineof = false;
          break;
        }
      ++__ret;
      __c = __sbin->snextc();
    }
      return __ret;
    }

    __copy_streambufs(basic_streambuf<_CharT, _Traits>* __sbin,
              basic_streambuf<_CharT, _Traits>* __sbout)
    {
      bool __ineof;
      return __copy_streambufs_eof(__sbin, __sbout, __ineof);
    }


only __ineof is false can indicate the failure, but it is ignored by
__copy_streambufs.


More information about the Gcc-bugs mailing list