Bug 1182723 - Properly handle self-assignment in nsTArray::operator=. r=mccr8, a=2.0+
--- 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();