libstdc++/9988: filebuf::overflow writes EOF to file

peturr02@ru.is peturr02@ru.is
Fri Mar 7 11:26:00 GMT 2003


>Number:         9988
>Category:       libstdc++
>Synopsis:       filebuf::overflow writes EOF to file
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Fri Mar 07 11:26:00 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator:     peturr02@ru.is
>Release:        gcc-3.2.1
>Organization:
>Environment:
Red Hat Linux 8.0
>Description:
If the parameter passed to filebuf::overflow equals traits_type::eof() it is written to the file.
>How-To-Repeat:
See attachment.
>Fix:
Check for EOF before writing character.
>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: text/plain; name="overflowbug.cc"
Content-Disposition: inline; filename="overflowbug.cc"

#include <fstream>

#undef NDEBUG
#include <cassert>

class Buf : public std::filebuf
{
public:
	int_type pub_overflow(int_type c = traits_type::eof())
		{ return std::filebuf::overflow(c); }
};

int main()
{
	using namespace std;

	Buf fb;
	fb.open("tmp", ios_base::out);

	fb.sputc('a');
	fb.pub_overflow('b');
	fb.pub_overflow();
	fb.sputc('c');
	fb.close();

	filebuf fbin;
	fbin.open("tmp", ios_base::in);
	int c;
	c = fbin.sbumpc();
	assert(c == 'a');
	c = fbin.sbumpc();
	assert(c == 'b');
	c = fbin.sbumpc();
	assert(c == 'c');
	c = fbin.sbumpc();
	assert(c == filebuf::traits_type::eof());
	fbin.close();

	return 0;
}



More information about the Gcc-prs mailing list