Bug 1270310 - Part 1: Make allocation in ConvertStringLineBreaks fallible. r=froydnj, r=peterv
☠☠ backed out by df9fd4cff088 ☠ ☠
authorEric Rahm <erahm@mozilla.com>
Thu, 05 May 2016 15:50:35 -0700
changeset 299077 3e2d76bd1f08108fc90859b51366efc3c8fa6c5c
parent 299076 1151e3a09e77a29b6089657df1b3e395430480e9
child 299078 4c302e1119e165fd389ced209be1ed34ef9e0231
push id77424
push userryanvm@gmail.com
push dateThu, 26 May 2016 03:30:11 +0000
treeherdermozilla-inbound@a789163346d9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj, peterv
bugs1270310
milestone49.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=peterv 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
@@ -5759,23 +5759,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!");
-      inputState->SetValue(value);
+
+      if (NS_FAILED(rv)) {
+        NS_ERROR("Converting linebreaks failed!");
+        return rv;
+      }
+
       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;