libstdc++/9507: filebuf::open handles ios_base::ate incorrectly

peturr02@ru.is peturr02@ru.is
Thu Jan 30 14:46:00 GMT 2003


>Number:         9507
>Category:       libstdc++
>Synopsis:       filebuf::open handles ios_base::ate incorrectly
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Jan 30 14:46:01 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator:     peturr02@ru.is
>Release:        gcc-3.2.1
>Organization:
>Environment:
Red Hat Linux 8.0
>Description:
When the flag ios_base::ate is passed to basic_filebuf::open, the filebuf tries to seek to the end of the file (as expected). If this seek fails, the file is closed before open returns (also as expected). However, the return value still indicates that open was successful, even though is_open is false after the call to open.
>How-To-Repeat:
See attachment.
>Fix:

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

#include <fstream>
#include <unistd.h>
#include <signal.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>

#undef NDEBUG
#include <cassert>

int main()
{
	using namespace std;

	signal(SIGPIPE, SIG_IGN);

	unlink("xxx");
	mkfifo("xxx", S_IRWXU);

	if (!fork())
	{
		filebuf fbuf;
		fbuf.open("xxx", ios_base::in);
		fbuf.sgetc();
		fbuf.close();

		exit(0);
	}

	filebuf fbuf;
	filebuf* r = fbuf.open("xxx", ios_base::out | ios_base::ate);
	assert(!fbuf.is_open());
	assert(r == NULL);

	unlink("xxx");
	return 0;
}



More information about the Gcc-prs mailing list