From 3e86298a2fb16ca161d0f7c9c6e8d39f739316a1 Mon Sep 17 00:00:00 2001 From: Aryeh Gregor Date: Tue, 19 Jun 2012 16:17:37 +0300 Subject: [PATCH] Bug 765799 - Uninitialized variable use in nsRange::InsertNode; r=smaug --- content/base/src/nsRange.cpp | 37 ++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/content/base/src/nsRange.cpp b/content/base/src/nsRange.cpp index 8f179a42a397..7d37e893b4fe 100644 --- a/content/base/src/nsRange.cpp +++ b/content/base/src/nsRange.cpp @@ -2081,28 +2081,29 @@ nsRange::InsertNode(nsIDOMNode* aNode) 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 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 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 tResultNode; res = referenceParentNode->InsertBefore(aNode, referenceNode, getter_AddRefs(tResultNode)); NS_ENSURE_SUCCESS(res, res);