From fb47271d472a18a85b917ba05cbbfb3f5bdf4e4c Mon Sep 17 00:00:00 2001 From: Mark Banner Date: Mon, 22 Dec 2008 15:32:19 +0000 Subject: [PATCH] Bug 399227 Crash @ nsTreeSelection::GetSingle, null mTree. r=enndeakin,sr=Neil --- .../base/src/tree/src/crashtests/399227-1.xul | 37 ++++++++++++++++ .../base/src/tree/src/crashtests/399227-2.xul | 43 +++++++++++++++++++ .../src/tree/src/crashtests/crashtests.list | 2 + .../xul/base/src/tree/src/nsTreeSelection.cpp | 22 +++++++--- 4 files changed, 99 insertions(+), 5 deletions(-) create mode 100644 layout/xul/base/src/tree/src/crashtests/399227-1.xul create mode 100644 layout/xul/base/src/tree/src/crashtests/399227-2.xul diff --git a/layout/xul/base/src/tree/src/crashtests/399227-1.xul b/layout/xul/base/src/tree/src/crashtests/399227-1.xul new file mode 100644 index 00000000000..cafeb815f85 --- /dev/null +++ b/layout/xul/base/src/tree/src/crashtests/399227-1.xul @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/layout/xul/base/src/tree/src/crashtests/399227-2.xul b/layout/xul/base/src/tree/src/crashtests/399227-2.xul new file mode 100644 index 00000000000..abfe12ce7c4 --- /dev/null +++ b/layout/xul/base/src/tree/src/crashtests/399227-2.xul @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/layout/xul/base/src/tree/src/crashtests/crashtests.list b/layout/xul/base/src/tree/src/crashtests/crashtests.list index decf92ebd3d..e3c7ae0c22a 100644 --- a/layout/xul/base/src/tree/src/crashtests/crashtests.list +++ b/layout/xul/base/src/tree/src/crashtests/crashtests.list @@ -4,6 +4,8 @@ load 309732-2.xul load 366583-1.xul load 380217-1.xul load 393665-1.xul +load 399227-1.xul +load 399227-2.xul load 399692-1.xhtml load 399715-1.xhtml load 409807-1.xul diff --git a/layout/xul/base/src/tree/src/nsTreeSelection.cpp b/layout/xul/base/src/tree/src/nsTreeSelection.cpp index 4f5ce665ce1..19bd221d6ae 100644 --- a/layout/xul/base/src/tree/src/nsTreeSelection.cpp +++ b/layout/xul/base/src/tree/src/nsTreeSelection.cpp @@ -299,6 +299,9 @@ NS_IMETHODIMP nsTreeSelection::SetTree(nsITreeBoxObject * aTree) NS_IMETHODIMP nsTreeSelection::GetSingle(PRBool* aSingle) { + if (!mTree) + return NS_ERROR_NULL_POINTER; + nsCOMPtr boxObject = do_QueryInterface(mTree); nsCOMPtr element; @@ -410,8 +413,8 @@ NS_IMETHODIMP nsTreeSelection::ToggleSelect(PRInt32 aIndex) else { if (!mFirstRange->Contains(aIndex)) { PRBool single; - GetSingle(&single); - if (!single) + rv = GetSingle(&single); + if (NS_SUCCEEDED(rv) && !single) rv = mFirstRange->Add(aIndex); } else @@ -430,7 +433,10 @@ NS_IMETHODIMP nsTreeSelection::ToggleSelect(PRInt32 aIndex) NS_IMETHODIMP nsTreeSelection::RangedSelect(PRInt32 aStartIndex, PRInt32 aEndIndex, PRBool aAugment) { PRBool single; - GetSingle(&single); + nsresult rv = GetSingle(&single); + if (NS_FAILED(rv)) + return rv; + if ((mFirstRange || (aStartIndex != aEndIndex)) && single) return NS_OK; @@ -452,7 +458,7 @@ NS_IMETHODIMP nsTreeSelection::RangedSelect(PRInt32 aStartIndex, PRInt32 aEndInd } mShiftSelectPivot = aStartIndex; - nsresult rv = SetCurrentIndex(aEndIndex); + rv = SetCurrentIndex(aEndIndex); if (NS_FAILED(rv)) return rv; @@ -534,7 +540,10 @@ NS_IMETHODIMP nsTreeSelection::SelectAll() PRInt32 rowCount; view->GetRowCount(&rowCount); PRBool single; - GetSingle(&single); + nsresult rv = GetSingle(&single); + if (NS_FAILED(rv)) + return rv; + if (rowCount == 0 || (rowCount > 1 && single)) return NS_OK; @@ -658,6 +667,9 @@ NS_IMETHODIMP nsTreeSelection::GetCurrentColumn(nsITreeColumn** aCurrentColumn) NS_IMETHODIMP nsTreeSelection::SetCurrentColumn(nsITreeColumn* aCurrentColumn) { + if (!mTree) { + return NS_ERROR_UNEXPECTED; + } if (mCurrentColumn == aCurrentColumn) { return NS_OK; }