From 4e94222e6013864898892cb564fc27654ff20e44 Mon Sep 17 00:00:00 2001 From: Cameron McCormack Date: Sat, 3 Aug 2013 14:11:06 +1000 Subject: [PATCH] Bug 899900 - Avoid null checking result of NS_NewBlahFrame. r=dbaron --- layout/forms/nsComboboxControlFrame.cpp | 9 +--- layout/forms/nsGfxButtonControlFrame.cpp | 8 ++-- layout/forms/nsListControlFrame.cpp | 4 +- layout/forms/nsSelectsAreaFrame.cpp | 8 ++-- layout/generic/nsFrameSetFrame.cpp | 60 ++++++++++-------------- layout/mathml/nsMathMLContainerFrame.cpp | 4 +- layout/tables/nsTableFrame.cpp | 6 +-- layout/xul/base/src/nsXULLabelFrame.cpp | 3 +- 8 files changed, 36 insertions(+), 66 deletions(-) diff --git a/layout/forms/nsComboboxControlFrame.cpp b/layout/forms/nsComboboxControlFrame.cpp index 585fbab052d..0f9d751938a 100644 --- a/layout/forms/nsComboboxControlFrame.cpp +++ b/layout/forms/nsComboboxControlFrame.cpp @@ -1330,19 +1330,12 @@ nsComboboxControlFrame::CreateFrameFor(nsIContent* aContent) nsRefPtr textStyleContext; textStyleContext = styleSet->ResolveStyleForNonElement(mStyleContext); - // Start by by creating our anonymous block frame + // Start by creating our anonymous block frame mDisplayFrame = new (shell) nsComboboxDisplayFrame(styleContext, this); - if (MOZ_UNLIKELY(!mDisplayFrame)) { - return nullptr; - } - mDisplayFrame->Init(mContent, this, nullptr); // Create a text frame and put it inside the block frame nsIFrame* textFrame = NS_NewTextFrame(shell, textStyleContext); - if (MOZ_UNLIKELY(!textFrame)) { - return nullptr; - } // initialize the text frame textFrame->Init(aContent, mDisplayFrame, nullptr); diff --git a/layout/forms/nsGfxButtonControlFrame.cpp b/layout/forms/nsGfxButtonControlFrame.cpp index 42d512695a8..4ecc0d7c928 100644 --- a/layout/forms/nsGfxButtonControlFrame.cpp +++ b/layout/forms/nsGfxButtonControlFrame.cpp @@ -100,11 +100,9 @@ nsGfxButtonControlFrame::CreateFrameFor(nsIContent* aContent) ResolveStyleForNonElement(mStyleContext); newFrame = NS_NewTextFrame(presContext->PresShell(), textStyleContext); - if (newFrame) { - // initialize the text frame - newFrame->Init(mTextContent, parentFrame, nullptr); - mTextContent->SetPrimaryFrame(newFrame); - } + // initialize the text frame + newFrame->Init(mTextContent, parentFrame, nullptr); + mTextContent->SetPrimaryFrame(newFrame); } return newFrame; diff --git a/layout/forms/nsListControlFrame.cpp b/layout/forms/nsListControlFrame.cpp index 11cc3aed47f..806fb5a4849 100644 --- a/layout/forms/nsListControlFrame.cpp +++ b/layout/forms/nsListControlFrame.cpp @@ -93,9 +93,7 @@ NS_NewListControlFrame(nsIPresShell* aPresShell, nsStyleContext* aContext) nsListControlFrame* it = new (aPresShell) nsListControlFrame(aPresShell, aPresShell->GetDocument(), aContext); - if (it) { - it->AddStateBits(NS_FRAME_INDEPENDENT_SELECTION); - } + it->AddStateBits(NS_FRAME_INDEPENDENT_SELECTION); return it; } diff --git a/layout/forms/nsSelectsAreaFrame.cpp b/layout/forms/nsSelectsAreaFrame.cpp index 9c0f8f87333..851364401de 100644 --- a/layout/forms/nsSelectsAreaFrame.cpp +++ b/layout/forms/nsSelectsAreaFrame.cpp @@ -14,11 +14,9 @@ NS_NewSelectsAreaFrame(nsIPresShell* aShell, nsStyleContext* aContext, uint32_t { nsSelectsAreaFrame* it = new (aShell) nsSelectsAreaFrame(aContext); - if (it) { - // We need NS_BLOCK_FLOAT_MGR to ensure that the options inside the select - // aren't expanded by right floats outside the select. - it->SetFlags(aFlags | NS_BLOCK_FLOAT_MGR); - } + // We need NS_BLOCK_FLOAT_MGR to ensure that the options inside the select + // aren't expanded by right floats outside the select. + it->SetFlags(aFlags | NS_BLOCK_FLOAT_MGR); return it; } diff --git a/layout/generic/nsFrameSetFrame.cpp b/layout/generic/nsFrameSetFrame.cpp index 407172976ab..0ff16fb649a 100644 --- a/layout/generic/nsFrameSetFrame.cpp +++ b/layout/generic/nsFrameSetFrame.cpp @@ -972,27 +972,21 @@ nsHTMLFramesetFrame::Reflow(nsPresContext* aPresContext, borderWidth, false, false); - if (MOZ_LIKELY(borderFrame != nullptr)) { - borderFrame->Init(mContent, this, nullptr); - mChildCount++; - mFrames.AppendFrame(nullptr, borderFrame); - mHorBorders[cellIndex.y-1] = borderFrame; - // set the neighbors for determining drag boundaries - borderFrame->mPrevNeighbor = lastRow; - borderFrame->mNextNeighbor = cellIndex.y; - } + borderFrame->Init(mContent, this, nullptr); + mChildCount++; + mFrames.AppendFrame(nullptr, borderFrame); + mHorBorders[cellIndex.y-1] = borderFrame; + // set the neighbors for determining drag boundaries + borderFrame->mPrevNeighbor = lastRow; + borderFrame->mNextNeighbor = cellIndex.y; } else { borderFrame = (nsHTMLFramesetBorderFrame*)mFrames.FrameAt(borderChildX); - if (MOZ_LIKELY(borderFrame != nullptr)) { - borderFrame->mWidth = borderWidth; - borderChildX++; - } - } - if (MOZ_LIKELY(borderFrame != nullptr)) { - nsSize borderSize(aDesiredSize.width, borderWidth); - ReflowPlaceChild(borderFrame, aPresContext, aReflowState, offset, borderSize); - borderFrame = nullptr; + borderFrame->mWidth = borderWidth; + borderChildX++; } + nsSize borderSize(aDesiredSize.width, borderWidth); + ReflowPlaceChild(borderFrame, aPresContext, aReflowState, offset, borderSize); + borderFrame = nullptr; offset.y += borderWidth; } else { if (cellIndex.x > 0) { // moved to next col in same row @@ -1008,27 +1002,21 @@ nsHTMLFramesetFrame::Reflow(nsPresContext* aPresContext, borderWidth, true, false); - if (MOZ_LIKELY(borderFrame != nullptr)) { - borderFrame->Init(mContent, this, nullptr); - mChildCount++; - mFrames.AppendFrame(nullptr, borderFrame); - mVerBorders[cellIndex.x-1] = borderFrame; - // set the neighbors for determining drag boundaries - borderFrame->mPrevNeighbor = lastCol; - borderFrame->mNextNeighbor = cellIndex.x; - } + borderFrame->Init(mContent, this, nullptr); + mChildCount++; + mFrames.AppendFrame(nullptr, borderFrame); + mVerBorders[cellIndex.x-1] = borderFrame; + // set the neighbors for determining drag boundaries + borderFrame->mPrevNeighbor = lastCol; + borderFrame->mNextNeighbor = cellIndex.x; } else { borderFrame = (nsHTMLFramesetBorderFrame*)mFrames.FrameAt(borderChildX); - if (MOZ_LIKELY(borderFrame != nullptr)) { - borderFrame->mWidth = borderWidth; - borderChildX++; - } - } - if (MOZ_LIKELY(borderFrame != nullptr)) { - nsSize borderSize(borderWidth, aDesiredSize.height); - ReflowPlaceChild(borderFrame, aPresContext, aReflowState, offset, borderSize); - borderFrame = nullptr; + borderFrame->mWidth = borderWidth; + borderChildX++; } + nsSize borderSize(borderWidth, aDesiredSize.height); + ReflowPlaceChild(borderFrame, aPresContext, aReflowState, offset, borderSize); + borderFrame = nullptr; } offset.x += borderWidth; } diff --git a/layout/mathml/nsMathMLContainerFrame.cpp b/layout/mathml/nsMathMLContainerFrame.cpp index 65e3d3e15c2..5e69a769f77 100644 --- a/layout/mathml/nsMathMLContainerFrame.cpp +++ b/layout/mathml/nsMathMLContainerFrame.cpp @@ -1551,9 +1551,7 @@ NS_NewMathMLmathBlockFrame(nsIPresShell* aPresShell, nsStyleContext* aContext, uint32_t aFlags) { nsMathMLmathBlockFrame* it = new (aPresShell) nsMathMLmathBlockFrame(aContext); - if (it) { - it->SetFlags(aFlags); - } + it->SetFlags(aFlags); return it; } diff --git a/layout/tables/nsTableFrame.cpp b/layout/tables/nsTableFrame.cpp index dcb97973d52..9409668cb0d 100644 --- a/layout/tables/nsTableFrame.cpp +++ b/layout/tables/nsTableFrame.cpp @@ -596,10 +596,8 @@ nsTableFrame::CreateAnonymousColGroupFrame(nsTableColGroupType aColGroupType) ResolveAnonymousBoxStyle(nsCSSAnonBoxes::tableColGroup, mStyleContext); // Create a col group frame nsIFrame* newFrame = NS_NewTableColGroupFrame(shell, colGroupStyle); - if (newFrame) { - ((nsTableColGroupFrame *)newFrame)->SetColType(aColGroupType); - newFrame->Init(colGroupContent, this, nullptr); - } + ((nsTableColGroupFrame *)newFrame)->SetColType(aColGroupType); + newFrame->Init(colGroupContent, this, nullptr); return (nsTableColGroupFrame *)newFrame; } diff --git a/layout/xul/base/src/nsXULLabelFrame.cpp b/layout/xul/base/src/nsXULLabelFrame.cpp index d2d9444722b..4dd4de0e9c0 100644 --- a/layout/xul/base/src/nsXULLabelFrame.cpp +++ b/layout/xul/base/src/nsXULLabelFrame.cpp @@ -15,8 +15,7 @@ NS_NewXULLabelFrame(nsIPresShell* aPresShell, nsStyleContext* aContext) { nsXULLabelFrame* it = new (aPresShell) nsXULLabelFrame(aContext); - if (it) - it->SetFlags(NS_BLOCK_FLOAT_MGR | NS_BLOCK_MARGIN_ROOT); + it->SetFlags(NS_BLOCK_FLOAT_MGR | NS_BLOCK_MARGIN_ROOT); return it; }