fix for blocker 80097 (nsSupportsStringImpl tries to memcpy to null -- causing crash in mailnews, see 80088). sr=scc

This commit is contained in:
dr%netscape.com 2001-05-10 23:05:44 +00:00
Родитель 4b7c9c8859
Коммит 664c05284b
1 изменённых файлов: 12 добавлений и 6 удалений

Просмотреть файл

@ -109,7 +109,7 @@ NS_IMPL_ISUPPORTS2(nsSupportsStringImpl, nsISupportsString,
nsISupportsPrimitive)
nsSupportsStringImpl::nsSupportsStringImpl()
: mData(nsnull)
: mData(0), mLength(0)
{
NS_INIT_ISUPPORTS();
}
@ -158,8 +158,11 @@ NS_IMETHODIMP nsSupportsStringImpl::SetDataWithLength(PRUint32 aLength,
const char *aData)
{
// if the new string length is the same as the old,
// just copy into the old buffer to avoid reallocating
if ((aLength == mLength) && aData) {
// just copy into the old buffer to avoid reallocating. we
// can further avoid reallocating by reusing the same
// buffer if aLength <= mLength, but there's high potential
// for bloat there. see bug 80097 for discussion.
if ((aLength == mLength) && aData && mData) {
nsCRT::memcpy(mData, aData, aLength * sizeof(char));
return NS_OK;
}
@ -218,7 +221,7 @@ NS_IMPL_ISUPPORTS2(nsSupportsWStringImpl, nsISupportsWString,
nsISupportsPrimitive)
nsSupportsWStringImpl::nsSupportsWStringImpl()
: mData(nsnull)
: mData(0), mLength(0)
{
NS_INIT_ISUPPORTS();
}
@ -267,8 +270,11 @@ NS_IMETHODIMP nsSupportsWStringImpl::SetDataWithLength(PRUint32 aLength,
const PRUnichar *aData)
{
// if the new string length is the same as the old,
// just copy into the old buffer to avoid reallocating
if ((aLength == mLength) && aData) {
// just copy into the old buffer to avoid reallocating. we
// can further avoid reallocating by reusing the same
// buffer if aLength <= mLength, but there's high potential
// for bloat there. see bug 80097 for discussion.
if ((aLength == mLength) && aData && mData) {
nsCRT::memcpy(mData, aData, aLength * sizeof(PRUnichar));
return NS_OK;
}