Bug 1270310 - Part 1: Make allocation in ConvertStringLineBreaks fallible. r=froydnj, r=smaug
authorEric Rahm <erahm@mozilla.com>
Thu, 05 May 2016 15:50:35 -0700
changeset 301416 39cf86d4874699644b4c2a97ff2b2a3e9fe0e1cc
parent 301415 05dbd2867765c127ad2d873ad502c2e3e6c6a211
child 301417 af33a66c68116bf306a9607cb3c9ad76deaa9b0f
push id30333
push usercbook@mozilla.com
push dateFri, 10 Jun 2016 13:39:58 +0000
treeherdermozilla-central@52679ce4756c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj, smaug
bugs1270310
milestone50.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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.
dom/html/HTMLInputElement.cpp
dom/html/HTMLTextAreaElement.cpp
xpcom/io/nsLinebreakConverter.cpp
--- a/dom/html/HTMLInputElement.cpp
+++ b/dom/html/HTMLInputElement.cpp
@@ -6310,22 +6310,27 @@ HTMLInputElement::SaveState()
            mType != NS_FORM_INPUT_HIDDEN) ||
           mType == NS_FORM_INPUT_PASSWORD || !mValueChanged) {
         break;
       }
 
       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;
   }
 
   if (inputState) {
     nsPresState* state = GetPrimaryPresState();
     if (state) {
       state->SetStateProperty(inputState);
--- a/dom/html/HTMLTextAreaElement.cpp
+++ b/dom/html/HTMLTextAreaElement.cpp
@@ -1080,17 +1080,21 @@ HTMLTextAreaElement::SaveState()
     if (state) {
       nsAutoString value;
       GetValueInternal(value, true);
 
       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;
+      }
 
       nsCOMPtr<nsISupportsString> pState =
         do_CreateInstance(NS_SUPPORTS_STRING_CONTRACTID);
       if (!pState) {
         return NS_ERROR_OUT_OF_MEMORY;
       }
       pState->SetData(value);
       state->SetStateProperty(pState);
--- a/xpcom/io/nsLinebreakConverter.cpp
+++ b/xpcom/io/nsLinebreakConverter.cpp
@@ -459,17 +459,19 @@ nsLinebreakConverter::ConvertStringLineB
     return NS_OK;
   }
 
   nsresult rv;
 
   // 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;
 
   rv = ConvertUnicharLineBreaksInSitu(&stringBuf,
                                       aSrcBreaks, aDestBreaks,
                                       aIoString.Length() + 1, &newLen);
   if (NS_FAILED(rv)) {
     return rv;