libstdc++/9761: filebuf::pbackfail discards previously put back characters

peturr02@ru.is peturr02@ru.is
Wed Feb 19 17:16:00 GMT 2003


>Number:         9761
>Category:       libstdc++
>Synopsis:       filebuf::pbackfail discards previously put back characters
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Feb 19 17:16:01 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator:     peturr02@ru.is
>Release:        gcc-3.2.1
>Organization:
>Environment:
Red Hat Linux 8.0
>Description:
If filebuf::sputbackc is called twice in a row, the result of the first sputbackc is lost. It would be better for the second sputbackc to fail than to corrupt the stream. Even better would be to support up to gptr() - eback() put backs.
>How-To-Repeat:
See attachment.
>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: text/plain; name="sputbackcbug3.cc"
Content-Disposition: inline; filename="sputbackcbug3.cc"

#include <fstream>

int main()
{
	using namespace std;

	filebuf fbuf;
	fbuf.open("sputbackcbug3.cc", ios_base::in);

	fbuf.sbumpc();
	fbuf.sbumpc();
	
	if (fbuf.sputbackc('a') == EOF)
		return 0;
	if (fbuf.sputbackc('b') == EOF)
		return 0;

	assert(fbuf.sbumpc() == 'b');
	assert(fbuf.sbumpc() == 'a');

	return 0;
}



More information about the Gcc-bugs mailing list