public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
From: peturr02@ru.is
To: gcc-gnats@gcc.gnu.org
Subject: libstdc++/9182: basic_filebuf<> does not report errors in codecvt<>::out
Date: Mon, 06 Jan 2003 09:26:00 -0000	[thread overview]
Message-ID: <20030106092415.6157.qmail@sources.redhat.com> (raw)


>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;
}


             reply	other threads:[~2003-01-06  9:26 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-01-06  9:26 peturr02 [this message]
2003-03-01 17:50 paolo
2003-03-08 14:04 paolo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20030106092415.6157.qmail@sources.redhat.com \
    --to=peturr02@ru.is \
    --cc=gcc-gnats@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).