Bug 1270310 - Part 1: Make allocation in ConvertStringLineBreaks fallible. r=froydnj, r=smaug

ConvertStringLineBreaks calls ConvertUnicharLineBreaksInSitu which uses
fallible allocation. We should make the potential allocation in |BeginWriting|
fallible as well and handle the failure. This also updates the callers to
|ConvertStringLineBreaks| to handle the error properly in release builds.
This commit is contained in:
Eric Rahm 2016-05-05 15:50:35 -07:00
parent a00c07b27f
commit f5b4b3b7b8
3 changed files with 15 additions and 4 deletions

View File

@ -6315,12 +6315,17 @@ HTMLInputElement::SaveState()
inputState = new HTMLInputElementState();
nsAutoString value;
GetValue(value);
DebugOnly<nsresult> rv =
nsresult rv =
nsLinebreakConverter::ConvertStringLineBreaks(
value,
nsLinebreakConverter::eLinebreakPlatform,
nsLinebreakConverter::eLinebreakContent);
NS_ASSERTION(NS_SUCCEEDED(rv), "Converting linebreaks failed!");
if (NS_FAILED(rv)) {
NS_ERROR("Converting linebreaks failed!");
return rv;
}
inputState->SetValue(value);
break;
}

View File

@ -1085,7 +1085,11 @@ HTMLTextAreaElement::SaveState()
value,
nsLinebreakConverter::eLinebreakPlatform,
nsLinebreakConverter::eLinebreakContent);
NS_ASSERTION(NS_SUCCEEDED(rv), "Converting linebreaks failed!");
if (NS_FAILED(rv)) {
NS_ERROR("Converting linebreaks failed!");
return rv;
}
nsCOMPtr<nsISupportsString> pState =
do_CreateInstance(NS_SUPPORTS_STRING_CONTRACTID);

View File

@ -464,7 +464,9 @@ nsLinebreakConverter::ConvertStringLineBreaks(nsString& aIoString,
// remember the old buffer in case
// we blow it away later
nsString::char_iterator stringBuf;
aIoString.BeginWriting(stringBuf);
if (!aIoString.BeginWriting(stringBuf, fallible)) {
return NS_ERROR_OUT_OF_MEMORY;
}
int32_t newLen;