aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaolo Carlini <pcarlini@unitus.it>2003-03-09 22:35:09 +0100
committerPaolo Carlini <paolo@gcc.gnu.org>2003-03-09 21:35:09 +0000
commit3006d728695e52d126b1e451937ac848f987b4b6 (patch)
treea7a1601651eed7f9a39a71a61a2b522f13771e6f
parente1a0421226407dced79d25e668f1128b24262bde (diff)
downloadgcc-3006d728695e52d126b1e451937ac848f987b4b6.zip
gcc-3006d728695e52d126b1e451937ac848f987b4b6.tar.gz
gcc-3006d728695e52d126b1e451937ac848f987b4b6.tar.bz2
re PR libstdc++/9988 (filebuf::overflow writes EOF to file)
2003-03-09 Paolo Carlini <pcarlini@unitus.it> PR libstdc++/9988 * include/bits/fstream.tcc (overflow): don't write EOF to file. * testsuite/27_io/filebuf_virtuals.cc (test15): Add. From-SVN: r64045
-rw-r--r--libstdc++-v3/ChangeLog6
-rw-r--r--libstdc++-v3/include/bits/fstream.tcc4
-rw-r--r--libstdc++-v3/testsuite/27_io/filebuf_virtuals.cc39
3 files changed, 48 insertions, 1 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index 81ac17e..14e9822 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,3 +1,9 @@
+2003-03-09 Paolo Carlini <pcarlini@unitus.it>
+
+ PR libstdc++/9988
+ * include/bits/fstream.tcc (overflow): don't write EOF to file.
+ * testsuite/27_io/filebuf_virtuals.cc (test15): Add.
+
2003-03-08 Jerry Quinn <jlquinn@optonline.net>
PR libstdc++/9561
diff --git a/libstdc++-v3/include/bits/fstream.tcc b/libstdc++-v3/include/bits/fstream.tcc
index 568c08c..2a31227 100644
--- a/libstdc++-v3/include/bits/fstream.tcc
+++ b/libstdc++-v3/include/bits/fstream.tcc
@@ -252,7 +252,9 @@ namespace std
if (__testout)
{
- if (__testput)
+ if (traits_type::eq_int_type(__c, traits_type::eof()))
+ __ret = traits_type::not_eof(__c);
+ else if (__testput)
{
*this->_M_out_cur = traits_type::to_char_type(__c);
_M_out_cur_move(1);
diff --git a/libstdc++-v3/testsuite/27_io/filebuf_virtuals.cc b/libstdc++-v3/testsuite/27_io/filebuf_virtuals.cc
index c60433c..2bccbd9 100644
--- a/libstdc++-v3/testsuite/27_io/filebuf_virtuals.cc
+++ b/libstdc++-v3/testsuite/27_io/filebuf_virtuals.cc
@@ -75,6 +75,7 @@ const char name_04[] = "filebuf_virtuals-4.txt"; // empty file, need to create
const char name_05[] = "filebuf_virtuals-5.txt"; // empty file, need to create
const char name_06[] = "filebuf_virtuals-6.txt"; // empty file, need to create
const char name_07[] = "filebuf_virtuals-7.txt"; // empty file, need to create
+const char name_08[] = "filebuf_virtuals-8.txt"; // empty file, need to create
class derived_filebuf: public std::filebuf
{
@@ -759,6 +760,43 @@ void test14()
fbuf1.close();
}
+
+class OverBuf : public std::filebuf
+{
+public:
+ int_type pub_overflow(int_type c = traits_type::eof())
+ { return std::filebuf::overflow(c); }
+};
+
+// libstdc++/9988
+void test15()
+{
+ using namespace std;
+ bool test = true;
+
+ OverBuf fb;
+ fb.open(name_08, ios_base::out | ios_base::trunc);
+
+ fb.sputc('a');
+ fb.pub_overflow('b');
+ fb.pub_overflow();
+ fb.sputc('c');
+ fb.close();
+
+ filebuf fbin;
+ fbin.open(name_08, ios_base::in);
+ filebuf::int_type c;
+ c = fbin.sbumpc();
+ VERIFY( c == 'a' );
+ c = fbin.sbumpc();
+ VERIFY( c == 'b' );
+ c = fbin.sbumpc();
+ VERIFY( c == 'c' );
+ c = fbin.sbumpc();
+ VERIFY( c == filebuf::traits_type::eof() );
+ fbin.close();
+}
+
main()
{
test01();
@@ -777,5 +815,6 @@ main()
test12();
test13();
test14();
+ test15();
return 0;
}