This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

libstdc++/9825: filebuf::sputbackc breaks sbumpc


>Number:         9825
>Category:       libstdc++
>Synopsis:       filebuf::sputbackc breaks sbumpc
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Feb 24 09:16:01 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator:     peturr02 at ru dot is
>Release:        gcc-3.2.1
>Organization:
>Environment:
Red Hat Linux 8.0
>Description:
Given the following:
filebuf fb;
[...]
fb.sputbackc('x');
fb.sbumpc();
fb.sbumpc(); // 1
fb.sbumpc(); // 2
The sbumpc in line 1 doesn't advance the read position, causing the sbumpc in line 2 to return the same character, instead of the next one.
>How-To-Repeat:
See attachment.
>Fix:

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

#include <fstream>
#include <cstdio>

#undef NDEBUG
#include <cassert>

int main()
{
	using namespace std;

	const char* str = "0123456789";
	
	FILE* fout = fopen("tmp", "w");
	fputs(str, fout);
	fclose(fout);

	filebuf fbuf;
	fbuf.open("tmp", ios_base::in);
	fbuf.sbumpc();
	fbuf.sputbackc('x');
	int c = fbuf.sbumpc();
	assert(c == 'x');
	c = fbuf.sbumpc();
	assert(c == '1');
	c = fbuf.sbumpc();
	assert(c == '2');
	fbuf.close();

	return 0;
}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]