This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
libstdc++/9825: filebuf::sputbackc breaks sbumpc
- From: peturr02 at ru dot is
- To: gcc-gnats at gcc dot gnu dot org
- Date: 24 Feb 2003 09:12:51 -0000
- Subject: libstdc++/9825: filebuf::sputbackc breaks sbumpc
- Reply-to: peturr02 at ru dot is
>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;
}