re PR libstdc++/10097 (filebuf::underflow drops characters.)

2003-03-17  Paolo Carlini  <pcarlini@unitus.it>
	    Petur Runolfsson  <peturr02@ru.is>

	PR libstdc++/10097
	* src/fstream.cc (basic_filebuf<char>::_M_underflow_common,
	basic_filebuf<wchar_t>::_M_underflow_common):
	if (gptr() < egptr()) return *gptr().
	* testsuite/27_io/filebuf_virtuals.cc (test16): Add.

	* testsuite/27_io/filebuf_members.cc (test_04): Minor
	changes: unlink fifo before making it, fix spelling error.

Co-Authored-By: Petur Runolfsson <peturr02@ru.is>

From-SVN: r64509
This commit is contained in:
Paolo Carlini 2003-03-18 00:50:40 +01:00 committed by Paolo Carlini
parent d41c4351fe
commit f7e70401d4
4 changed files with 100 additions and 18 deletions

View File

@ -1,3 +1,15 @@
2003-03-17 Paolo Carlini <pcarlini@unitus.it>
Petur Runolfsson <peturr02@ru.is>
PR libstdc++/10097
* src/fstream.cc (basic_filebuf<char>::_M_underflow_common,
basic_filebuf<wchar_t>::_M_underflow_common):
if (gptr() < egptr()) return *gptr().
* testsuite/27_io/filebuf_virtuals.cc (test16): Add.
* testsuite/27_io/filebuf_members.cc (test_04): Minor
changes: unlink fifo before making it, fix spelling error.
2003-03-17 Benjamin Kosnik <bkoz@redhat.com>
* testsuite/Makefile.am (CLEANFILES): Add tmp*.

View File

@ -1,6 +1,6 @@
// File based streams -*- C++ -*-
// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002
// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003
// Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
@ -52,15 +52,14 @@ namespace std
// normal buffers and jet outta here before expensive
// fileops happen...
if (_M_pback_init)
_M_pback_destroy();
if (_M_in_cur && _M_in_cur < _M_in_end)
{
_M_pback_destroy();
if (_M_in_cur < _M_in_end)
{
__ret = traits_type::to_int_type(*_M_in_cur);
if (__bump)
_M_in_cur_move(1);
return __ret;
}
__ret = traits_type::to_int_type(*_M_in_cur);
if (__bump)
_M_in_cur_move(1);
return __ret;
}
// Sync internal and external buffers.
@ -135,15 +134,14 @@ namespace std
// normal buffers and jet outta here before expensive
// fileops happen...
if (_M_pback_init)
_M_pback_destroy();
if (_M_in_cur && _M_in_cur < _M_in_end)
{
_M_pback_destroy();
if (_M_in_cur < _M_in_end)
{
__ret = traits_type::to_int_type(*_M_in_cur);
if (__bump)
_M_in_cur_move(1);
return __ret;
}
__ret = traits_type::to_int_type(*_M_in_cur);
if (__bump)
_M_in_cur_move(1);
return __ret;
}
// Sync internal and external buffers.

View File

@ -133,9 +133,10 @@ test_04()
const char* name = "tmp_fifo1";
signal(SIGPIPE, SIG_IGN);
unlink(name);
if (0 != mkfifo(name, S_IRWXU))
{
std::cerr << "failed to creat fifo" << std::endl;
std::cerr << "failed to create fifo" << std::endl;
exit(-1);
}

View File

@ -21,6 +21,11 @@
// 27.8.1.4 Overridden virtual functions
#include <fstream>
#include <unistd.h>
#include <signal.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <locale>
#include <testsuite_hooks.h>
@ -798,6 +803,71 @@ void test15()
fbin.close();
}
class UnderBuf : public std::filebuf
{
public:
int_type
pub_underflow()
{ return underflow(); }
std::streamsize
pub_showmanyc()
{ return showmanyc(); }
};
// libstdc++/10097
void test16()
{
using namespace std;
bool test = true;
const char* name = "tmp_fifo1";
signal(SIGPIPE, SIG_IGN);
unlink(name);
if (0 != mkfifo(name, S_IRWXU))
{
VERIFY( false );
}
int fval = fork();
if (fval == -1)
{
unlink(name);
VERIFY( false );
}
else if (fval == 0)
{
filebuf fbout;
fbout.open(name, ios_base::out);
fbout.sputn("0123456789", 10);
fbout.pubsync();
sleep(2);
fbout.close();
exit(0);
}
UnderBuf fb;
fb.open(name, ios_base::in);
sleep(1);
fb.sgetc();
streamsize n = fb.pub_showmanyc();
while (n > 0)
{
--n;
UnderBuf::int_type c = fb.pub_underflow();
VERIFY( c != UnderBuf::traits_type::eof() );
fb.sbumpc();
}
fb.close();
}
main()
{
test01();
@ -817,5 +887,6 @@ main()
test13();
test14();
test15();
test16();
return 0;
}