Bug 960591 - Prevent implicitly constructing nsTArray<E> elements from E* pointers - r=ehsan
authorBenoit Jacob <bjacob@mozilla.com>
Fri, 17 Jan 2014 11:54:19 -0500
changeset 163980 7eb615c086e89f50885b4dbca4b3c7367a9d5ff5
parent 163979 4804658f1be45e5bdf759b25e6d0970a1444ffdb
child 163981 524b5b1776473bdcac482305fcea310d69b2c7de
push id38605
push userbjacob@mozilla.com
push dateFri, 17 Jan 2014 16:59:06 +0000
treeherdermozilla-inbound@7eb615c086e8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan
bugs960591
milestone29.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 960591 - Prevent implicitly constructing nsTArray<E> elements from E* pointers - r=ehsan
xpcom/glue/nsTArray.h
--- a/xpcom/glue/nsTArray.h
+++ b/xpcom/glue/nsTArray.h
@@ -519,16 +519,21 @@ public:
     // ints.  We don't want that because it can be a performance issue
     // and people don't expect it; nsTArray should work like a regular
     // C/C++ array in this respect.
     new (static_cast<void *>(e)) E;
   }
   // Invoke the copy-constructor in place.
   template<class A>
   static inline void Construct(E *e, const A &arg) {
+    typedef typename mozilla::RemoveCV<E>::Type E_NoCV;
+    typedef typename mozilla::RemoveCV<A>::Type A_NoCV;
+    static_assert(!mozilla::IsSame<E_NoCV*, A_NoCV>::value,
+                  "For safety, we disallow constructing nsTArray<E> elements "
+                  "from E* pointers. See bug 960591.");
     new (static_cast<void *>(e)) E(arg);
   }
   // Invoke the destructor in place.
   static inline void Destruct(E *e) {
     e->~E();
   }
 };