This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC 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]

[v3] Fix ios_base storage crash


ios_base doesn't set up the [pi]word storage until _M_init() is called, so a
derived class breaks if it tries to use the storage.

Fixed with this patch.  Ok for 3.3 and mainline?

2003-03-06  Jerry Quinn  <jlquinn at optonline dot net>

	* src/ios.cc (ios_base::_M_init): Remove _M_word_size.
	(ios_base::ios_base): Set _M_word, _M_word_size.
	(ios_base::~ios_base): Remove redundant test.
	* testsuite/27_io/ios_base_storage.cc (test03): New.

Index: src/ios.cc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/src/ios.cc,v
retrieving revision 1.33.2.2
diff -u -r1.33.2.2 ios.cc
--- src/ios.cc	5 Mar 2003 04:40:07 -0000	1.33.2.2
+++ src/ios.cc	6 Mar 2003 05:53:55 -0000
@@ -288,7 +288,6 @@
     _M_width = 0;
     _M_flags = skipws | dec;
     _M_callbacks = 0;
-    _M_word_size = 0;
     _M_ios_locale = locale();
   }  
   
@@ -302,7 +301,8 @@
     return __old;
   }
 
-  ios_base::ios_base() : _M_callbacks(0), _M_word(0)
+  ios_base::ios_base() : _M_callbacks(0), _M_word(_M_local_word),
+			 _M_word_size(_S_local_word_size)
   {
     // Do nothing: basic_ios::init() does it.  
     // NB: _M_callbacks and _M_word must be zero for non-initialized
@@ -314,7 +314,7 @@
   {
     _M_call_callbacks(erase_event);
     _M_dispose_callbacks();
-    if (_M_word && _M_word != _M_local_word) 
+    if (_M_word != _M_local_word) 
       {
 	delete [] _M_word;
 	_M_word = 0;
Index: testsuite/27_io/ios_base_storage.cc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/testsuite/27_io/ios_base_storage.cc,v
retrieving revision 1.5.20.3
diff -u -r1.5.20.3 ios_base_storage.cc
--- testsuite/27_io/ios_base_storage.cc	5 Mar 2003 21:42:31 -0000	1.5.20.3
+++ testsuite/27_io/ios_base_storage.cc	6 Mar 2003 05:53:55 -0000
@@ -138,10 +138,25 @@
 
 }
 
+class derived : public std::ios_base
+{
+public:
+  derived() {}
+};
+
+void test03()
+{
+  derived d;
+
+  d.pword(0) = &d;
+  d.iword(0) = 1;
+}
+
 int main(void)
 {
   __gnu_cxx_test::set_memory_limits();
   test01();
   test02();
+  test03();
   return 0;
 }


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