Bug 479057 Concatenating empty strings can result in bogus copying r=bsmedberg

This commit is contained in:
Neil Rashbrook 2009-03-04 09:50:22 +00:00
parent c07aefc948
commit e2e4ed438f
2 changed files with 18 additions and 7 deletions

View File

@ -434,8 +434,17 @@ nsTSubstring_CharT::Assign( const substring_tuple_type& tuple )
size_type length = tuple.Length();
if (ReplacePrep(0, mLength, length) && length)
// don't use ReplacePrep here because it changes the length
char_type* oldData;
PRUint32 oldFlags;
if (MutatePrep(length, &oldData, &oldFlags)) {
if (oldData)
::ReleaseData(oldData, oldFlags);
tuple.WriteTo(mData, length);
mData[length] = 0;
mLength = length;
}
}
void

View File

@ -552,17 +552,18 @@ PRBool test_concat_2()
return PR_FALSE;
}
#if 0
PRBool test_concat_3()
{
nsCString a("a"), b("b");
nsCString result;
nsCString ab("ab"), c("c");
// THIS DOES NOT COMPILE
const nsACString& r = a + b;
result = ab + result + c;
if (strcmp(result.get(), "abc") == 0)
return PR_TRUE;
return PR_TRUE;
printf("[result=%s]\n", result.get());
return PR_FALSE;
}
#endif
PRBool test_xpidl_string()
{
@ -997,6 +998,7 @@ tests[] =
{ "test_fixed_string", test_fixed_string },
{ "test_concat", test_concat },
{ "test_concat_2", test_concat_2 },
{ "test_concat_3", test_concat_3 },
{ "test_xpidl_string", test_xpidl_string },
{ "test_empty_assign", test_empty_assign },
{ "test_set_length", test_set_length },