Bug 765799 - Uninitialized variable use in nsRange::InsertNode; r=smaug
authorAryeh Gregor <ayg@aryeh.name>
Tue, 19 Jun 2012 16:17:37 +0300
changeset 99736 e82037b16e21f595923a895c7d99f1f905ebf82e
parent 99735 7ef99e28eed99581cb4256f551ca19bc16d4151a
child 99737 9d826056332b34245f19a93a1a07281847711114
push id1729
push userlsblakk@mozilla.com
push dateMon, 16 Jul 2012 20:02:43 +0000
treeherdermozilla-aurora@f4e75e148951 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs765799
milestone16.0a1
Bug 765799 - Uninitialized variable use in nsRange::InsertNode; r=smaug
content/base/src/nsRange.cpp
--- a/content/base/src/nsRange.cpp
+++ b/content/base/src/nsRange.cpp
@@ -2076,38 +2076,39 @@ nsRange::InsertNode(nsIDOMNode* aNode)
     res = tStartContainer->GetChildNodes(getter_AddRefs(tChildList));
     NS_ENSURE_SUCCESS(res, res);
 
     // find the insertion point in the DOM and insert the Node
     res = tChildList->Item(tStartOffset, getter_AddRefs(referenceNode));
     NS_ENSURE_SUCCESS(res, res);
   }
 
-  // We might need to update the end to include the new node (bug 433662)
+  // We might need to update the end to include the new node (bug 433662).
+  // Ideally we'd only do this if needed, but it's tricky to know when it's
+  // needed in advance (bug 765799).
   PRInt32 newOffset;
 
-  if (Collapsed()) {
-    if (referenceNode) {
-      newOffset = IndexOf(referenceNode);
-    } else {
-      PRUint32 length;
-      res = tChildList->GetLength(&length);
-      NS_ENSURE_SUCCESS(res, res);
-      newOffset = length;
-    }
-
-    nsCOMPtr<nsINode> node = do_QueryInterface(aNode);
-    NS_ENSURE_STATE(node);
-    if (node->NodeType() == nsIDOMNode::DOCUMENT_FRAGMENT_NODE) {
-      newOffset += node->GetChildCount();
-    } else {
-      newOffset++;
-    }
+  if (referenceNode) {
+    newOffset = IndexOf(referenceNode);
+  } else {
+    PRUint32 length;
+    res = tChildList->GetLength(&length);
+    NS_ENSURE_SUCCESS(res, res);
+    newOffset = length;
   }
 
+  nsCOMPtr<nsINode> node = do_QueryInterface(aNode);
+  NS_ENSURE_STATE(node);
+  if (node->NodeType() == nsIDOMNode::DOCUMENT_FRAGMENT_NODE) {
+    newOffset += node->GetChildCount();
+  } else {
+    newOffset++;
+  }
+
+  // Now actually insert the node
   nsCOMPtr<nsIDOMNode> tResultNode;
   res = referenceParentNode->InsertBefore(aNode, referenceNode, getter_AddRefs(tResultNode));
   NS_ENSURE_SUCCESS(res, res);
 
   if (Collapsed()) {
     return SetEnd(referenceParentNode, newOffset);
   }
   return NS_OK;