This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
[Patch] Fix libstdc++/10097
- From: Paolo Carlini <pcarlini at unitus dot it>
- To: "libstdc++ at gcc dot gnu dot org" <libstdc++ at gcc dot gnu dot org>
- Cc: Benjamin Kosnik <bkoz at redhat dot com>, Nathan Myers <ncm at cantrip dot org>
- Date: Sun, 16 Mar 2003 11:39:17 +0100
- Subject: [Patch] Fix libstdc++/10097
Hi,
the below fixes the problem essentially by unconditionally
doing:
if (gptr() < egptr())
return *gptr();
on top of underflow, as suggested by Pétur and favored
by Nathan.
Tested x86-linux. If approved, seems good for 3.3 too.
In general, my plans are as follows:
1- Have in fixes for 9533 and 10097: proposals already
posted.
2- Have in Pétur's patches for 9964, 9581/9870: both
ok with me!
3- Return to 9701 to fix the second part: seems easy in
the light of some obervations from Nathan.
4- Finally return to 9423/9024, and then 9875/9178.
Nathan? Benjamin?
Thanks,
Paolo.
///////////
2003-03-16 Paolo Carlini <pcarlini at unitus dot it>
Petur Runolfsson <peturr02 at ru dot 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 (test18): Add.
* testsuite/27_io/filebuf_members.cc (test_04): Minor
changes: unlink fifo before making it, fix spelling error.
diff -prN libstdc++-v3-curr/src/fstream.cc libstdc++-v3/src/fstream.cc
*** libstdc++-v3-curr/src/fstream.cc Sat Mar 15 19:16:19 2003
--- libstdc++-v3/src/fstream.cc Sat Mar 15 19:18:01 2003
***************
*** 1,6 ****
// File based streams -*- C++ -*-
! // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002
// Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
--- 1,6 ----
// File based streams -*- C++ -*-
! // 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
*************** namespace std
*** 52,66 ****
// normal buffers and jet outta here before expensive
// fileops happen...
if (_M_pback_init)
{
! _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;
! }
}
// Sync internal and external buffers.
--- 52,65 ----
// 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)
{
! __ret = traits_type::to_int_type(*_M_in_cur);
! if (__bump)
! _M_in_cur_move(1);
! return __ret;
}
// Sync internal and external buffers.
*************** namespace std
*** 135,149 ****
// normal buffers and jet outta here before expensive
// fileops happen...
if (_M_pback_init)
{
! _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;
! }
}
// Sync internal and external buffers.
--- 134,147 ----
// 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)
{
! __ret = traits_type::to_int_type(*_M_in_cur);
! if (__bump)
! _M_in_cur_move(1);
! return __ret;
}
// Sync internal and external buffers.
diff -prN libstdc++-v3-curr/testsuite/27_io/filebuf_members.cc libstdc++-v3/testsuite/27_io/filebuf_members.cc
*** libstdc++-v3-curr/testsuite/27_io/filebuf_members.cc Tue Feb 4 19:08:45 2003
--- libstdc++-v3/testsuite/27_io/filebuf_members.cc Sat Mar 15 21:49:52 2003
*************** void
*** 129,138 ****
test_04()
{
signal(SIGPIPE, SIG_IGN);
!
if (0 != mkfifo("xxx", S_IRWXU))
{
! std::cerr << "failed to creat fifo" << std::endl;
exit(-1);
}
--- 129,139 ----
test_04()
{
signal(SIGPIPE, SIG_IGN);
!
! unlink("xxx");
if (0 != mkfifo("xxx", S_IRWXU))
{
! std::cerr << "failed to create fifo" << std::endl;
exit(-1);
}
diff -prN libstdc++-v3-curr/testsuite/27_io/filebuf_virtuals.cc libstdc++-v3/testsuite/27_io/filebuf_virtuals.cc
*** libstdc++-v3-curr/testsuite/27_io/filebuf_virtuals.cc Thu Mar 13 10:50:13 2003
--- libstdc++-v3/testsuite/27_io/filebuf_virtuals.cc Sat Mar 15 20:06:48 2003
*************** void test17()
*** 889,894 ****
--- 889,957 ----
VERIFY( sum == written );
}
+ class UnderBuf : public std::filebuf
+ {
+ public:
+ int_type
+ pub_underflow()
+ { return underflow(); }
+
+ std::streamsize
+ pub_showmanyc()
+ { return showmanyc(); }
+ };
+
+ // libstdc++/10097
+ void test18()
+ {
+ using namespace std;
+ bool test = true;
+
+ signal(SIGPIPE, SIG_IGN);
+ unlink("xxx");
+
+ if (0 != mkfifo("xxx", S_IRWXU))
+ {
+ VERIFY( false );
+ }
+
+ int fval = fork();
+ if (fval == -1)
+ {
+ unlink("xxx");
+ VERIFY( 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);
+ }
+
+ UnderBuf fb;
+ fb.open("xxx", 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();
*************** main()
*** 910,914 ****
--- 973,978 ----
test15();
test16();
test17();
+ test18();
return 0;
}