Patchwork [google,gcc-4_7,integration] Add more lightweight checks for dangling vectors

login
register
mail settings
Submitter Paul Pluzhnikov
Date Jan. 22, 2013, 5:21 a.m.
Message ID <ye6qzk016be3.fsf@elbrus2.mtv.corp.google.com>
Download mbox | patch
Permalink /patch/214340/
State New
Headers show

Comments

Paul Pluzhnikov - Jan. 22, 2013, 5:21 a.m.
This patch sets destructed vector into an invalid state, such that
subsequent calls to begin(), end(), size(), etc. all throw logic_error.

Google ref b/7248326

Ok for google/gcc-4_7 and google/integration?

Thanks,
--
Paul Pluzhnikov
Diego Novillo - Jan. 22, 2013, 2:13 p.m.
On Tue, Jan 22, 2013 at 12:21 AM, Paul Pluzhnikov
<ppluzhnikov@google.com> wrote:
> This patch sets destructed vector into an invalid state, such that
> subsequent calls to begin(), end(), size(), etc. all throw logic_error.
>
> Google ref b/7248326
>
> Ok for google/gcc-4_7 and google/integration?

OK.

Diego.

Patch

Index: libstdc++-v3/include/bits/stl_vector.h
===================================================================
--- libstdc++-v3/include/bits/stl_vector.h	(revision 195356)
+++ libstdc++-v3/include/bits/stl_vector.h	(working copy)
@@ -159,7 +159,12 @@  _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
 
       ~_Vector_base()
       { _M_deallocate(this->_M_impl._M_start, this->_M_impl._M_end_of_storage
-		      - this->_M_impl._M_start); }
+		      - this->_M_impl._M_start);
+#if __google_stl_debug_dangling_vector
+        this->_M_impl._M_start = 0;
+        this->_M_impl._M_finish = reinterpret_cast<_Tp*>(~0UL);
+#endif
+      }
 
     public:
       _Vector_impl _M_impl;