Bug 1182723 - Properly handle self-assignment in nsTArray::operator=. r=mccr8, a=2.1+
authorBirunthan Mohanathas <birunthan@mohanathas.com>
Tue, 21 Jul 2015 09:42:58 -0700
changeset 222177 55edd9de0b57
parent 222176 def978d33afc
child 222178 40ff0897f4a4
push id559
push userryanvm@gmail.com
push dateThu, 23 Jul 2015 02:06:46 +0000
treeherdermozilla-b2g34_v2_1@55edd9de0b57 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmccr8, 2
bugs1182723
milestone34.0
Bug 1182723 - Properly handle self-assignment in nsTArray::operator=. r=mccr8, a=2.1+
xpcom/glue/nsTArray.h
--- a/xpcom/glue/nsTArray.h
+++ b/xpcom/glue/nsTArray.h
@@ -783,17 +783,19 @@ public:
     return *reinterpret_cast<const FallibleTArray<E>*>(this);
   }
 
   // The array's assignment operator performs a 'deep' copy of the given
   // array.  It is optimized to reuse existing storage if possible.
   // @param aOther The array object to copy.
   self_type& operator=(const self_type& aOther)
   {
-    ReplaceElementsAt(0, Length(), aOther.Elements(), aOther.Length());
+    if (this != &aOther) {
+      ReplaceElementsAt(0, Length(), aOther.Elements(), aOther.Length());
+    }
     return *this;
   }
 
   // Return true if this array has the same length and the same
   // elements as |aOther|.
   template<typename Allocator>
   bool operator==(const nsTArray_Impl<E, Allocator>& aOther) const
   {