This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Patch/RFC] libstdc++/9024


Hi everyone, hi Benjamin.

This PR is about the effect of pubsetbuf(0, 0): in the
current code, being M_buf_size_opt set to zero, a next open
doesn't allocate at all an internal buffer.

This seems not correct when the 'in' openmode flag is true.

Is the fix below the right approach? I have positively
tested it on x86-linux, as usual.

Paolo.

////////////
2002-12-20  Paolo Carlini  <pcarlini@unitus.it>

	PR libstdc++/9024
	* include/bits/fstream.tcc
	(basic_filebuf::_M_allocate_internal_buffer): When the
	'in' openmode flag is true, _M_buf_size cannot be zero but
	at least 1 (for an unbuffered stream).
	(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	Fri Dec 20 23:54:09 2002
*************** namespace std
*** 44,56 ****
      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,66 ----
      basic_filebuf<_CharT, _Traits>::
      _M_allocate_internal_buffer()
      {
!       if (!_M_buf)
  	{
! 	  if (_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;
! 	    }
! 	  else if (_M_mode & ios_base::in)
! 	    {
! 	      _M_buf_size =  1;
  
! 	      _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();
--- 98,105 ----
  	  _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;
  }

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]