From 2186dda269e4ddd2d8f78b6b7c340b087d799d71 Mon Sep 17 00:00:00 2001 From: Ehsan Akhgari Date: Fri, 18 Jun 2010 17:01:08 -0400 Subject: [PATCH] Bug 572598 - Part 3: Improve error checking in nsEditor::GetStartNodeAndOffset; r=roc --- editor/libeditor/base/nsEditor.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/editor/libeditor/base/nsEditor.cpp b/editor/libeditor/base/nsEditor.cpp index aeeda9e53092..cf167b521b0c 100644 --- a/editor/libeditor/base/nsEditor.cpp +++ b/editor/libeditor/base/nsEditor.cpp @@ -3770,23 +3770,23 @@ nsEditor::GetStartNodeAndOffset(nsISelection *aSelection, nsCOMPtrselPrivate(do_QueryInterface(aSelection)); nsCOMPtr enumerator; nsresult result = selPrivate->GetEnumerator(getter_AddRefs(enumerator)); - if (NS_FAILED(result) || !enumerator) - return NS_ERROR_FAILURE; - + NS_ENSURE_SUCCESS(result, result); + NS_ENSURE_TRUE(enumerator, NS_ERROR_FAILURE); + enumerator->First(); nsCOMPtr currentItem; - if (NS_FAILED(enumerator->CurrentItem(getter_AddRefs(currentItem)))) - return NS_ERROR_FAILURE; + result = enumerator->CurrentItem(getter_AddRefs(currentItem)); + NS_ENSURE_SUCCESS(result, result); nsCOMPtr range( do_QueryInterface(currentItem) ); NS_ENSURE_TRUE(range, NS_ERROR_FAILURE); - - if (NS_FAILED(range->GetStartContainer(outStartNode))) - return NS_ERROR_FAILURE; - - if (NS_FAILED(range->GetStartOffset(outStartOffset))) - return NS_ERROR_FAILURE; - + + result = range->GetStartContainer(outStartNode); + NS_ENSURE_SUCCESS(result, result); + + result = range->GetStartOffset(outStartOffset); + NS_ENSURE_SUCCESS(result, result); + return NS_OK; }