This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
[Alternate patch] libstdc++/9024
- From: Paolo Carlini <pcarlini at unitus dot it>
- To: Paolo Carlini <pcarlini at unitus dot it>
- Cc: "libstdc++ at gcc dot gnu dot org" <libstdc++ at gcc dot gnu dot org>, bkoz <bkoz at redhat dot com>
- Date: Sat, 21 Dec 2002 22:42:17 +0100
- Subject: [Alternate patch] libstdc++/9024
- References: <3E03A776.4000203@unitus.it>
Hi again,
reading the standard closer (27.8.1.4,10), "unbuffered" implies
that pbase() and pptr() always return null.
Therefore my first attempt seems not correct when the 'in'
openmode flag is true and _at the same time_ the 'out' openmode
flag is true too.
The below, tested x86-linux, fixes that problem.
Paolo.
/////////
2002-12-21 Paolo Carlini <pcarlini@unitus.it>
PR libstdc++/9024
* include/bits/fstream.tcc
(basic_filebuf::_M_allocate_internal_buffer): When the
'out' openmode flag is not true and _M_buf_size_opt == 0
(unbuffered) _M_buf_size shall be non zero to allow reading.
(basic_filebuf::open): Tweak.
* testsuite/27_io/filebuf_virtuals.cc: Add test07.
diff -prN libstdc++-v3-orig/include/bits/fstream.tcc libstdc++-v3/include/bits/fstream.tcc
*** libstdc++-v3-orig/include/bits/fstream.tcc Mon Dec 16 19:22:58 2002
--- libstdc++-v3/include/bits/fstream.tcc Sat Dec 21 22:24:06 2002
*************** namespace std
*** 44,55 ****
basic_filebuf<_CharT, _Traits>::
_M_allocate_internal_buffer()
{
! if (!_M_buf && _M_buf_size_opt)
{
! _M_buf_size = _M_buf_size_opt;
// Allocate internal buffer.
! _M_buf = new char_type[_M_buf_size];
_M_buf_allocated = true;
}
}
--- 44,55 ----
basic_filebuf<_CharT, _Traits>::
_M_allocate_internal_buffer()
{
! if (!_M_buf && (_M_buf_size_opt || !(_M_mode & ios_base::out)))
{
! _M_buf_size = _M_buf_size_opt > 0 ? _M_buf_size_opt : 1;
// Allocate internal buffer.
! _M_buf = new char_type[_M_buf_size];
_M_buf_allocated = true;
}
}
*************** namespace std
*** 88,95 ****
_M_file.open(__s, __mode);
if (this->is_open())
{
- _M_allocate_internal_buffer();
_M_mode = __mode;
// Setup initial position of buffer.
_M_set_indeterminate();
--- 88,95 ----
_M_file.open(__s, __mode);
if (this->is_open())
{
_M_mode = __mode;
+ _M_allocate_internal_buffer();
// Setup initial position of buffer.
_M_set_indeterminate();
diff -prN libstdc++-v3-orig/testsuite/27_io/filebuf_virtuals.cc libstdc++-v3/testsuite/27_io/filebuf_virtuals.cc
*** libstdc++-v3-orig/testsuite/27_io/filebuf_virtuals.cc Wed Jul 31 04:47:36 2002
--- libstdc++-v3/testsuite/27_io/filebuf_virtuals.cc Fri Dec 20 23:32:05 2002
*************** void test06()
*** 514,519 ****
--- 514,535 ----
VERIFY( buffer[0] == 'a' );
}
+ // libstdc++/9024
+ void test07()
+ {
+ using namespace std;
+
+ bool test = true;
+ char buf[512];
+
+ filebuf fbuf01;
+
+ fbuf01.pubsetbuf(0, 0);
+ fbuf01.open("filebuf_virtuals-1.txt", ios_base::in);
+
+ VERIFY( fbuf01.sgetn(buf, 512) );
+ }
+
main()
{
test01();
*************** main()
*** 524,528 ****
--- 540,546 ----
test05();
test06();
+ test07();
+
return 0;
}