Bug 1182723 - Properly handle self-assignment in nsTArray::operator=. r=mccr8, a=2.0+ B2G_2_0_END
authorBirunthan Mohanathas <birunthan@mohanathas.com>
Tue, 21 Jul 2015 09:42:58 -0700
changeset 204946 2e6f1d4deff9cfe476b6bdcb1744afa708383afc
parent 204945 a6823b98409746cff51ca630cb08bca9f999d8bd
child 204947 b6057e17f8560bc9bf76f9a36dbf013cca4157ee
push id865
push userryanvm@gmail.com
push dateThu, 23 Jul 2015 02:30:36 +0000
treeherdermozilla-b2g32_v2_0@2e6f1d4deff9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmccr8, 2
bugs1182723
milestone32.0
Bug 1182723 - Properly handle self-assignment in nsTArray::operator=. r=mccr8, a=2.0+
xpcom/glue/nsTArray.h
--- a/xpcom/glue/nsTArray.h
+++ b/xpcom/glue/nsTArray.h
@@ -815,17 +815,19 @@ public:
   operator const FallibleTArray<E>&() const {
     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 other  The array object to copy.
   self_type& operator=(const self_type& other) {
-    ReplaceElementsAt(0, Length(), other.Elements(), other.Length());
+    if (this != &other) {
+      ReplaceElementsAt(0, Length(), other.Elements(), other.Length());
+    }
     return *this;
   }
 
   // Return true if this array has the same length and the same
   // elements as |other|.
   template<typename Allocator>
   bool operator==(const nsTArray_Impl<E, Allocator>& other) const {
     size_type len = Length();