This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
libstdc++/9182: basic_filebuf<> does not report errors in codecvt<>::out
- From: peturr02 at ru dot is
- To: gcc-gnats at gcc dot gnu dot org
- Date: 6 Jan 2003 09:24:15 -0000
- Subject: libstdc++/9182: basic_filebuf<> does not report errors in codecvt<>::out
- Reply-to: peturr02 at ru dot is
>Number: 9182
>Category: libstdc++
>Synopsis: basic_filebuf<> does not report errors in codecvt<>::out
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Mon Jan 06 01:26:00 PST 2003
>Closed-Date:
>Last-Modified:
>Originator: peturr02@ru.is
>Release: gcc-3.2.1
>Organization:
>Environment:
Red Hat Linux 8.0
>Description:
basic_filebuf<>::sync and overflow do not write out any characters if codecvt<>::out returns error, but they still return success (as if the buffers had been written successfully).
>How-To-Repeat:
See attachment
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: text/plain; name="errorbug.cc"
Content-Disposition: inline; filename="errorbug.cc"
#include <locale>
#include <cwchar>
#include <fstream>
template <typename InternT, typename ExternT = char,
typename StateT = std::mbstate_t>
class errorcvt : public std::codecvt<InternT, ExternT, StateT>
{
typedef std::codecvt<InternT, ExternT, StateT> Base;
public:
explicit errorcvt(std::size_t refs = 0)
: Base(refs)
{
}
protected:
virtual std::codecvt_base::result
do_out(StateT&, const InternT* from, const InternT*,
const InternT*& from_next, ExternT* to, ExternT*,
ExternT*& to_next) const
{
from_next = from;
to_next = to;
return error;
}
virtual bool do_always_noconv() const throw()
{
return false;
}
};
#undef NDEBUG
#include <cassert>
int main()
{
std::locale loc;
loc = std::locale(loc, new errorcvt<char>);
loc = std::locale(loc, new errorcvt<wchar_t>);
std::filebuf fbuf1;
fbuf1.pubimbue(loc);
//fbuf1.pubsetbuf(0, 0);
fbuf1.open("tmp", std::ios_base::out | std::ios_base::trunc);
// Write some characters, should fail as nothing gets written
// to the file.
int n = fbuf1.sputn("abcd", 4); // Should fail if unbuffered
int r = fbuf1.pubsync(); // Should fail if buffered
fbuf1.close();
// Verify that file is empty
std::filebuf fbuf2;
fbuf2.open("tmp", std::ios_base::in);
assert(fbuf2.sgetc() == std::filebuf::traits_type::eof());
// Either sputn or pubsync or both should have failed
assert(n < 4 || r != 0);
return 0;
}