This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
[Patch] Fix libstdc++/9423
- From: Paolo Carlini <pcarlini at unitus dot it>
- To: libstdc++ at gcc dot gnu dot org
- Cc: bkoz <bkoz at redhat dot com>
- Date: Sun, 13 Apr 2003 10:19:27 +0200
- Subject: [Patch] Fix libstdc++/9423
Hi.
Benjamin's 27_io testsuite reshuffle enables to fix libstdc++/9423
independently from other issues.
Tested x86-linux, ok?
Paolo.
/////////
2003-04-13 Paolo Carlini <pcarlini at unitus dot it>
PR libstdc++/9423
* include/bits/fstream.tcc (basic_filebuf::setbuf):
If setbuf(0, 0) is called after open but before the first
I/O operation is guaranteed to work.
* testsuite/27_io/basic_filebuf/setbuf/char/1.cc (test_05): Tweak.
* include/bits/fstream.tcc (basic_filebuf::setbuf): Don't set
_M_out_end, _M_set_indeterminate() does it.
diff -urN libstdc++-v3-orig/include/bits/fstream.tcc libstdc++-v3/include/bits/fstream.tcc
--- libstdc++-v3-orig/include/bits/fstream.tcc 2003-04-12 18:30:29.000000000 +0200
+++ libstdc++-v3/include/bits/fstream.tcc 2003-04-13 00:19:13.000000000 +0200
@@ -413,8 +413,19 @@
basic_filebuf<_CharT, _Traits>::
setbuf(char_type* __s, streamsize __n)
{
- if (!this->is_open() && __s == 0 && __n == 0)
- this->_M_buf_size = 0;
+ if (__s == 0 && __n == 0)
+ {
+ this->_M_buf_size = 0;
+ // If setbuf(0, 0) is called before the first I/O
+ // operation, is guaranteed to work, even if is_open()
+ // is true. In that case, however, we destroy the
+ // current internal array.
+ if (this->is_open())
+ {
+ _M_destroy_internal_buffer();
+ _M_set_indeterminate();
+ }
+ }
else if (__s && __n)
{
// This is implementation-defined behavior, and assumes
@@ -428,8 +439,6 @@
// Step 2: Use the external array.
this->_M_buf = __s;
this->_M_buf_size = __n;
- // Consistently set the end of buffer pointer.
- this->_M_out_end = this->_M_buf + this->_M_buf_size;
_M_set_indeterminate();
}
_M_last_overflowed = false;
diff -urN libstdc++-v3-orig/testsuite/27_io/basic_filebuf/setbuf/char/1.cc libstdc++-v3/testsuite/27_io/basic_filebuf/setbuf/char/1.cc
--- libstdc++-v3-orig/testsuite/27_io/basic_filebuf/setbuf/char/1.cc 2003-04-10 09:15:28.000000000 +0200
+++ libstdc++-v3/testsuite/27_io/basic_filebuf/setbuf/char/1.cc 2003-04-13 09:56:36.000000000 +0200
@@ -74,12 +74,26 @@
testbuf f_tmp;
f_tmp.open(name_01, ios_base::out | ios_base::in);
+
+ // setbuf
+ // pubsetbuf(char_type* s, streamsize n)
+ f_tmp.pubsetbuf(0, 0);
+ VERIFY( f_tmp.check_pointers() );
+ // OK, no I/O operations before pubsetbuf(0, 0) (libstdc++/9423).
+ }
+
+ {
+ testbuf f_tmp;
+
+ f_tmp.open(name_01, ios_base::out | ios_base::in);
int_type c1 = f_tmp.sbumpc();
// setbuf
// pubsetbuf(char_type* s, streamsize n)
f_tmp.pubsetbuf(0, 0);
- VERIFY( !f_tmp.check_pointers() );
+ VERIFY( f_tmp.check_pointers() );
+ // Undefined behaviour from now on, however, since an I/O operation
+ // has already occurred (sbumpc() above).
}
}