Check for self-assignment in wxArrayString
Assigning array to itself destroyed its contents -- check for this now. Closes #17619.
This commit is contained in:
parent
3572c2c654
commit
985ff1e26e
@ -89,7 +89,14 @@ wxArrayString::wxArrayString(const wxArrayString& src)
|
||||
wxArrayString& wxArrayString::operator=(const wxArrayString& src)
|
||||
{
|
||||
if ( m_nSize > 0 )
|
||||
{
|
||||
// Do this test here to avoid unnecessary overhead when assigning to an
|
||||
// empty array, in that case there is no harm in self-assignment.
|
||||
if ( &src == this )
|
||||
return *this;
|
||||
|
||||
Clear();
|
||||
}
|
||||
|
||||
Copy(src);
|
||||
|
||||
|
@ -350,6 +350,13 @@ void ArraysTestCase::wxStringArrayTest()
|
||||
wxArrayString a6;
|
||||
a6.Add("Foo");
|
||||
a6.Insert(a6[0], 1, 100);
|
||||
|
||||
wxArrayString a7;
|
||||
a7 = a7;
|
||||
CPPUNIT_ASSERT_EQUAL( 0, a7.size() );
|
||||
a7.Add("Bar");
|
||||
a7 = a7;
|
||||
CPPUNIT_ASSERT_EQUAL( 1, a7.size() );
|
||||
}
|
||||
|
||||
void ArraysTestCase::SortedArray()
|
||||
|
Loading…
Reference in New Issue
Block a user