Bug 328755 - Fix the ConvertAndWrite crash. r=bz

This commit is contained in:
James Kitchener 2014-02-18 09:57:44 -05:00
parent ee57f16151
commit 56f7c1ed2b

View File

@ -559,6 +559,12 @@ ConvertAndWrite(const nsAString& aString,
startCharLength = charLength; startCharLength = charLength;
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
if (!charLength) {
// Nothing to write. Besides, a length 0 string has an immutable buffer, so
// attempts to null-terminate it will crash.
return NS_OK;
}
nsAutoCString charXferString; nsAutoCString charXferString;
if (!charXferString.SetLength(charLength, fallible_t())) if (!charXferString.SetLength(charLength, fallible_t()))
return NS_ERROR_OUT_OF_MEMORY; return NS_ERROR_OUT_OF_MEMORY;