diff options
author | Paolo Carlini <pcarlini@unitus.it> | 2003-03-18 00:50:40 +0100 |
---|---|---|
committer | Paolo Carlini <paolo@gcc.gnu.org> | 2003-03-17 23:50:40 +0000 |
commit | f7e70401d4135fc690034f57cb236a050fa4c91b (patch) | |
tree | 8b6fb9d753bf7f28130ed78ea76ae7e8a940bdf8 | |
parent | d41c4351fecd21f7602c66ac78c594557b87f5c4 (diff) | |
download | gcc-f7e70401d4135fc690034f57cb236a050fa4c91b.zip gcc-f7e70401d4135fc690034f57cb236a050fa4c91b.tar.gz gcc-f7e70401d4135fc690034f57cb236a050fa4c91b.tar.bz2 |
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
-rw-r--r-- | libstdc++-v3/ChangeLog | 12 | ||||
-rw-r--r-- | libstdc++-v3/src/fstream.cc | 32 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/27_io/filebuf_members.cc | 3 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/27_io/filebuf_virtuals.cc | 71 |
4 files changed, 100 insertions, 18 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 555c135..1209342 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -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*. diff --git a/libstdc++-v3/src/fstream.cc b/libstdc++-v3/src/fstream.cc index 9352f47..8280a66 100644 --- a/libstdc++-v3/src/fstream.cc +++ b/libstdc++-v3/src/fstream.cc @@ -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. diff --git a/libstdc++-v3/testsuite/27_io/filebuf_members.cc b/libstdc++-v3/testsuite/27_io/filebuf_members.cc index d6a9b35..79dfa25 100644 --- a/libstdc++-v3/testsuite/27_io/filebuf_members.cc +++ b/libstdc++-v3/testsuite/27_io/filebuf_members.cc @@ -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); } diff --git a/libstdc++-v3/testsuite/27_io/filebuf_virtuals.cc b/libstdc++-v3/testsuite/27_io/filebuf_virtuals.cc index a881086..6699d80 100644 --- a/libstdc++-v3/testsuite/27_io/filebuf_virtuals.cc +++ b/libstdc++-v3/testsuite/27_io/filebuf_virtuals.cc @@ -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; } |