libstdc++/10097: filebuf::underflow drops characters.

peturr02@ru.is peturr02@ru.is
Sat Mar 15 13:07:00 GMT 2003


>Number:         10097
>Category:       libstdc++
>Synopsis:       filebuf::underflow drops characters.
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Mar 15 10:56:00 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator:     peturr02@ru.is
>Release:        gcc-3.2.2
>Organization:
>Environment:
Red Hat Linux 8.0
>Description:
filebuf::underflow discards characters that are already in the buffer, this causes those characters to be lost when reading from a pipe.
>How-To-Repeat:
See attachment.
>Fix:

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

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

#undef NDEBUG
#include <cassert>

class Buf : public std::filebuf
{
public:
	int_type pub_underflow()
		{ return underflow(); }
	std::streamsize pub_showmanyc()
		{ return showmanyc(); }
};

int main()
{
	using namespace std;

	signal(SIGPIPE, SIG_IGN);
	unlink("xxx");
  
	if (0 != mkfifo("xxx", S_IRWXU))
	{
		assert(false);
	}
	
	int fval = fork();
	if (fval == -1)
	{
		unlink("xxx");
		assert(false);
	}
	else if (fval == 0)
	{
		filebuf fbout;
		fbout.open("xxx", ios_base::out);
		fbout.sputn("0123456789", 10);
		fbout.pubsync();
		sleep(2);
		fbout.close();
		exit(0);
	}

	Buf fb;
	fb.open("xxx", ios_base::in);
	sleep(1);

	fb.sgetc();
	streamsize n = fb.pub_showmanyc();

	while (n > 0)
	{
		--n;

		Buf::int_type c = fb.pub_underflow();
		assert(c != Buf::traits_type::eof());

		fb.sbumpc();
	}

	fb.close();

	return 0;
}



More information about the Gcc-bugs mailing list