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]

[google gcc-4_7,gcc-4_8,integration] Relax vector validity checks


Greetings,

The vector validity checks introduced here:
http://gcc.gnu.org/ml/gcc-patches/2011-09/msg00415.html

proved too strict: older versions of GCC used to do this:

  _M_start = _M_end = _M_end_of_storage = new_allocator(sizeof(T) * n)

even when n == 0, and we have code compiled by such version linked in
with new code, and failing the check.

Google ref b/9198806

Attached patch relaxes the check, while still catching dangling vector
accesses.

Ok for google/gcc_4-7, gcc-4_8 and integration branches?

Thanks,

--
Paul Pluzhnikov

Index: libstdc++-v3/include/bits/stl_vector.h
===================================================================
--- libstdc++-v3/include/bits/stl_vector.h	(revision 199461)
+++ libstdc++-v3/include/bits/stl_vector.h	(working copy)
@@ -244,12 +244,27 @@
 
       bool _M_is_valid() const
       {
-        return (this->_M_impl._M_end_of_storage == 0
-		&& this->_M_impl._M_start == 0
-		&& this->_M_impl._M_finish == 0)
-	      || (this->_M_impl._M_start <= this->_M_impl._M_finish
-		  && this->_M_impl._M_finish <= this->_M_impl._M_end_of_storage
-		  && this->_M_impl._M_start < this->_M_impl._M_end_of_storage);
+        if (this->_M_impl._M_end_of_storage == 0
+	    && this->_M_impl._M_start == 0
+	    && this->_M_impl._M_finish == 0)
+	  return true;
+
+	if (this->_M_impl._M_start <= this->_M_impl._M_finish
+	    && this->_M_impl._M_finish <= this->_M_impl._M_end_of_storage)
+	  {
+	    if (this->_M_impl._M_start < this->_M_impl._M_end_of_storage)
+	      return true;
+	    else if (this->_M_impl._M_start == this->_M_impl._M_end_of_storage
+		     && this->_M_impl._M_start == this->_M_impl._M_finish)
+	      {
+		pointer _0xcdcd;
+
+		__builtin_memset(&_0xcdcd, 0xcd, sizeof(_0xcdcd));
+		return this->_M_impl._M_finish != _0xcdcd;
+	      }
+	  }
+
+	return false;
       }
 
     public:


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