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++/10063: Regression: stdio_filebuf broken


>Number:         10063
>Category:       libstdc++
>Synopsis:       Regression: stdio_filebuf broken
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Mar 13 19:36:00 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator:     peturr02 at ru dot is
>Release:        gcc 3.4 cvs from 20030312
>Organization:
>Environment:
Red Hat Linux 8.0
>Description:
stdio_filebuf on current mainline now bypasses the FILE* used to construct it and uses the underlying file descriptor. This breaks any program that does I/O on a FILE* before constructing a stdio_filebuf from it.

>How-To-Repeat:
See attachment.
>Fix:

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

#include <ext/stdio_filebuf.h>
#include <cstdio>
#include <fstream>

#undef NDEBUG
#include <cassert>

void test1()
{
	using namespace std;

	FILE* file = fopen("tmp", "w");
	putc('0', file);
	putc('1', file);

	{
		using namespace __gnu_cxx;

		stdio_filebuf<char> sbuf (file, ios_base::out);
		sbuf.sputc('2');
		sbuf.sputc('3');
	}

	putc('4', file);
	
	fclose(file);

	filebuf fbuf;
	fbuf.open("tmp", ios_base::in);
	
	char buf[10];
	streamsize n = fbuf.sgetn(buf, sizeof(buf));	
	
	fbuf.close();

	assert(n == 5);
	assert(!memcmp(buf, "01234", 5));
}

void test2()
{
	using namespace std;

	filebuf fbuf;
	fbuf.open("tmp", ios_base::out | ios_base::trunc);
	fbuf.sputn("01234", 5);
	fbuf.close();

	FILE* file = fopen("tmp", "r");
	int c = getc(file);
	assert(c == '0');
	c = getc(file);
	assert(c == '1');
	
	{
		using namespace __gnu_cxx;

		stdio_filebuf<char> sbuf (file, ios_base::in);
		c = sbuf.sbumpc();
		assert(c == '2');
		c = sbuf.sbumpc();
		assert(c == '3');
		c = sbuf.sbumpc();
		assert(c == '4');
		c = sbuf.sgetc();
		assert(c == EOF);
	}

	fclose(file);
}

int main()
{
	test1();
	test2();

	return 0;
}


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