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++/9425: filebuf::pbackfail broken


>Number:         9425
>Category:       libstdc++
>Synopsis:       filebuf::pbackfail broken
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Jan 23 19:06:01 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator:     peturr02@ru.is
>Release:        gcc-3.2.1
>Organization:
>Environment:
Red Hat Linux 8.0
>Description:
basic_filebuf<>::pbackfail calls basic_filebuf<>::seekoff, but fails to check the return value. If seekoff fails for some reason (including, but not limited to codecvt<>::encoding() <= 0), strange things happen.
>How-To-Repeat:
See attachment.
>Fix:

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

#include <fstream>
#include <locale>
#include <cstdio>
#include <cwchar>

#undef NDEBUG
#include <cassert>

using namespace std;

class Variable : public codecvt<char, char, mbstate_t>
{
	int do_encoding() const throw() { return 0; }
};

int main()
{
	char buf[BUFSIZ];
	
	filebuf fb01;
	fb01.open("filebuf_virtuals-1.txt", ios_base::in);
	streamsize sz1 = fb01.sgetn(buf, BUFSIZ);
	assert(sz1 == BUFSIZ);

	fb01.sgetc();
	int n1 = fb01.sputbackc('a');
	if (n1 == EOF)
		return 0;

	streamsize sz2 = fb01.sgetn(buf, BUFSIZ);
	assert(buf[0] == 'a');
	fb01.close();

	filebuf fb02;
	locale loc;
	loc = locale(loc, new Variable);
	fb02.pubimbue(loc);
	fb02.open("filebuf_virtuals-1.txt", ios_base::in);
	streamsize sz3 = fb02.sgetn(buf, BUFSIZ);
	assert(sz3 == BUFSIZ);

	fb02.sgetc();
	int n2 = fb02.sputbackc('a');
	if (n2 == EOF)
		return 0;

	streamsize sz4 = fb02.sgetn(buf, BUFSIZ);
	assert(buf[0] == 'a');
	assert(sz4 == sz2);


	return 0;
}


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