sc/qa/unit/tiledrendering/tiledrendering.cxx | 72 +++++++++++---------- sd/qa/unit/tiledrendering/tiledrendering.cxx | 84 +++++++++++++------------ sw/qa/extras/tiledrendering/tiledrendering.cxx | 41 ++++++------ sw/source/core/layout/atrfrm.cxx | 83 ++++++++++++------------ sw/source/core/txtnode/ndtxt.cxx | 4 - 5 files changed, 152 insertions(+), 132 deletions(-)
New commits: commit e75b67c68ace40cc25ef525003d334fc56de6423 Author: Caolán McNamara <caol...@redhat.com> Date: Sat Dec 16 15:58:31 2017 +0000 coverity#1426171 Unchecked dynamic_cast and coverity#1426170 Unchecked dynamic_cast coverity#1426164 Unchecked dynamic_cast coverity#1426165 Unchecked dynamic_cast and duplicated lines look like cnp gone wrong Change-Id: I195204e9d0a4d591fbe210241203a17b22b25ec1 Reviewed-on: https://gerrit.libreoffice.org/46603 Tested-by: Jenkins <c...@libreoffice.org> Reviewed-by: Caolán McNamara <caol...@redhat.com> Tested-by: Caolán McNamara <caol...@redhat.com> diff --git a/sc/qa/unit/tiledrendering/tiledrendering.cxx b/sc/qa/unit/tiledrendering/tiledrendering.cxx index 7d80d8349ded..0fe4d7a4b5c4 100644 --- a/sc/qa/unit/tiledrendering/tiledrendering.cxx +++ b/sc/qa/unit/tiledrendering/tiledrendering.cxx @@ -1440,14 +1440,16 @@ void ScTiledRenderingTest::testDocumentRepair() int nView2 = SfxLokHelper::getView(); CPPUNIT_ASSERT(pView1 != pView2); { - std::unique_ptr<SfxPoolItem> pItem1; - std::unique_ptr<SfxPoolItem> pItem2; - pView1->GetViewFrame()->GetBindings().QueryState(SID_DOC_REPAIR, pItem1); - pView2->GetViewFrame()->GetBindings().QueryState(SID_DOC_REPAIR, pItem2); - CPPUNIT_ASSERT(dynamic_cast< const SfxBoolItem* >(pItem1.get())); - CPPUNIT_ASSERT(dynamic_cast< const SfxBoolItem* >(pItem2.get())); - CPPUNIT_ASSERT_EQUAL(false, dynamic_cast< const SfxBoolItem* >(pItem1.get())->GetValue()); - CPPUNIT_ASSERT_EQUAL(false, dynamic_cast< const SfxBoolItem* >(pItem2.get())->GetValue()); + std::unique_ptr<SfxPoolItem> xItem1; + std::unique_ptr<SfxPoolItem> xItem2; + pView1->GetViewFrame()->GetBindings().QueryState(SID_DOC_REPAIR, xItem1); + pView2->GetViewFrame()->GetBindings().QueryState(SID_DOC_REPAIR, xItem2); + const SfxBoolItem* pItem1 = dynamic_cast< const SfxBoolItem* >(xItem1.get()); + const SfxBoolItem* pItem2 = dynamic_cast< const SfxBoolItem* >(xItem2.get()); + CPPUNIT_ASSERT(pItem1); + CPPUNIT_ASSERT(pItem2); + CPPUNIT_ASSERT_EQUAL(false, pItem1->GetValue()); + CPPUNIT_ASSERT_EQUAL(false, pItem2->GetValue()); } // Insert a character in the second view. @@ -1459,14 +1461,16 @@ void ScTiledRenderingTest::testDocumentRepair() pModelObj->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, awt::Key::RETURN); Scheduler::ProcessEventsToIdle(); { - std::unique_ptr<SfxPoolItem> pItem1; - std::unique_ptr<SfxPoolItem> pItem2; - pView1->GetViewFrame()->GetBindings().QueryState(SID_DOC_REPAIR, pItem1); - pView2->GetViewFrame()->GetBindings().QueryState(SID_DOC_REPAIR, pItem2); - CPPUNIT_ASSERT(dynamic_cast< const SfxBoolItem* >(pItem1.get())); - CPPUNIT_ASSERT(dynamic_cast< const SfxBoolItem* >(pItem2.get())); - CPPUNIT_ASSERT_EQUAL(true, dynamic_cast< const SfxBoolItem* >(pItem1.get())->GetValue()); - CPPUNIT_ASSERT_EQUAL(true, dynamic_cast< const SfxBoolItem* >(pItem2.get())->GetValue()); + std::unique_ptr<SfxPoolItem> xItem1; + std::unique_ptr<SfxPoolItem> xItem2; + pView1->GetViewFrame()->GetBindings().QueryState(SID_DOC_REPAIR, xItem1); + pView2->GetViewFrame()->GetBindings().QueryState(SID_DOC_REPAIR, xItem2); + const SfxBoolItem* pItem1 = dynamic_cast< const SfxBoolItem* >(xItem1.get()); + const SfxBoolItem* pItem2 = dynamic_cast< const SfxBoolItem* >(xItem2.get()); + CPPUNIT_ASSERT(pItem1); + CPPUNIT_ASSERT(pItem2); + CPPUNIT_ASSERT_EQUAL(true, pItem1->GetValue()); + CPPUNIT_ASSERT_EQUAL(true, pItem2->GetValue()); } comphelper::LibreOfficeKit::setActive(false); @@ -1489,14 +1493,16 @@ void ScTiledRenderingTest::testLanguageStatus() CPPUNIT_ASSERT(pView1 != pView2); const OUString aLangBolivia("Spanish (Bolivia)"); { - std::unique_ptr<SfxPoolItem> pItem1; - std::unique_ptr<SfxPoolItem> pItem2; - pView1->GetViewFrame()->GetBindings().QueryState(SID_LANGUAGE_STATUS, pItem1); - pView2->GetViewFrame()->GetBindings().QueryState(SID_LANGUAGE_STATUS, pItem2); - CPPUNIT_ASSERT(dynamic_cast< const SfxStringItem* >(pItem1.get())); - CPPUNIT_ASSERT(dynamic_cast< const SfxStringItem* >(pItem2.get())); - CPPUNIT_ASSERT(!dynamic_cast< const SfxStringItem* >(pItem1.get())->GetValue().isEmpty()); - CPPUNIT_ASSERT(!dynamic_cast< const SfxStringItem* >(pItem1.get())->GetValue().isEmpty()); + std::unique_ptr<SfxPoolItem> xItem1; + std::unique_ptr<SfxPoolItem> xItem2; + pView1->GetViewFrame()->GetBindings().QueryState(SID_LANGUAGE_STATUS, xItem1); + pView2->GetViewFrame()->GetBindings().QueryState(SID_LANGUAGE_STATUS, xItem2); + const SfxStringItem* pItem1 = dynamic_cast<const SfxStringItem*>(xItem1.get()); + const SfxStringItem* pItem2 = dynamic_cast<const SfxStringItem*>(xItem2.get()); + CPPUNIT_ASSERT(pItem1); + CPPUNIT_ASSERT(pItem2); + CPPUNIT_ASSERT(!pItem1->GetValue().isEmpty()); + CPPUNIT_ASSERT(!pItem2->GetValue().isEmpty()); } { @@ -1506,14 +1512,16 @@ void ScTiledRenderingTest::testLanguageStatus() } { - std::unique_ptr<SfxPoolItem> pItem1; - std::unique_ptr<SfxPoolItem> pItem2; - pView1->GetViewFrame()->GetBindings().QueryState(SID_LANGUAGE_STATUS, pItem1); - pView2->GetViewFrame()->GetBindings().QueryState(SID_LANGUAGE_STATUS, pItem2); - CPPUNIT_ASSERT(dynamic_cast< const SfxStringItem* >(pItem1.get())); - CPPUNIT_ASSERT(dynamic_cast< const SfxStringItem* >(pItem2.get())); - CPPUNIT_ASSERT_EQUAL(aLangBolivia, dynamic_cast< const SfxStringItem* >(pItem1.get())->GetValue()); - CPPUNIT_ASSERT_EQUAL(aLangBolivia, dynamic_cast< const SfxStringItem* >(pItem1.get())->GetValue()); + std::unique_ptr<SfxPoolItem> xItem1; + std::unique_ptr<SfxPoolItem> xItem2; + pView1->GetViewFrame()->GetBindings().QueryState(SID_LANGUAGE_STATUS, xItem1); + pView2->GetViewFrame()->GetBindings().QueryState(SID_LANGUAGE_STATUS, xItem2); + const SfxStringItem* pItem1 = dynamic_cast<const SfxStringItem*>(xItem1.get()); + const SfxStringItem* pItem2 = dynamic_cast<const SfxStringItem*>(xItem2.get()); + CPPUNIT_ASSERT(pItem1); + CPPUNIT_ASSERT(pItem2); + CPPUNIT_ASSERT_EQUAL(aLangBolivia, pItem1->GetValue()); + CPPUNIT_ASSERT_EQUAL(aLangBolivia, pItem2->GetValue()); } } diff --git a/sd/qa/unit/tiledrendering/tiledrendering.cxx b/sd/qa/unit/tiledrendering/tiledrendering.cxx index 24c4354217a8..63080a2461e2 100644 --- a/sd/qa/unit/tiledrendering/tiledrendering.cxx +++ b/sd/qa/unit/tiledrendering/tiledrendering.cxx @@ -1813,12 +1813,12 @@ void SdTiledRenderingTest::testDisableUndoRepair() pXImpressDocument->postKeyEvent(LOK_KEYEVENT_KEYUP, 'h', 0); Scheduler::ProcessEventsToIdle(); { - std::unique_ptr<SfxPoolItem> pItem1; - std::unique_ptr<SfxPoolItem> pItem2; - pView1->GetViewFrame()->GetBindings().QueryState(SID_UNDO, pItem1); - pView2->GetViewFrame()->GetBindings().QueryState(SID_UNDO, pItem2); - CPPUNIT_ASSERT(!dynamic_cast< const SfxUInt32Item* >(pItem1.get())); - const SfxUInt32Item* pUInt32Item = dynamic_cast<const SfxUInt32Item*>(pItem2.get()); + std::unique_ptr<SfxPoolItem> xItem1; + std::unique_ptr<SfxPoolItem> xItem2; + pView1->GetViewFrame()->GetBindings().QueryState(SID_UNDO, xItem1); + pView2->GetViewFrame()->GetBindings().QueryState(SID_UNDO, xItem2); + CPPUNIT_ASSERT(!dynamic_cast< const SfxUInt32Item* >(xItem1.get())); + const SfxUInt32Item* pUInt32Item = dynamic_cast<const SfxUInt32Item*>(xItem2.get()); CPPUNIT_ASSERT(pUInt32Item); CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt32>(SID_REPAIRPACKAGE), pUInt32Item->GetValue()); } @@ -1832,12 +1832,12 @@ void SdTiledRenderingTest::testDisableUndoRepair() pXImpressDocument->postKeyEvent(LOK_KEYEVENT_KEYUP, 'c', 0); Scheduler::ProcessEventsToIdle(); { - std::unique_ptr<SfxPoolItem> pItem1; - std::unique_ptr<SfxPoolItem> pItem2; - pView1->GetViewFrame()->GetBindings().QueryState(SID_UNDO, pItem1); - pView2->GetViewFrame()->GetBindings().QueryState(SID_UNDO, pItem2); - CPPUNIT_ASSERT(!dynamic_cast< const SfxUInt32Item* >(pItem2.get())); - const SfxUInt32Item* pUInt32Item = dynamic_cast<const SfxUInt32Item*>(pItem1.get()); + std::unique_ptr<SfxPoolItem> xItem1; + std::unique_ptr<SfxPoolItem> xItem2; + pView1->GetViewFrame()->GetBindings().QueryState(SID_UNDO, xItem1); + pView2->GetViewFrame()->GetBindings().QueryState(SID_UNDO, xItem2); + CPPUNIT_ASSERT(!dynamic_cast< const SfxUInt32Item* >(xItem2.get())); + const SfxUInt32Item* pUInt32Item = dynamic_cast<const SfxUInt32Item*>(xItem1.get()); CPPUNIT_ASSERT(pUInt32Item); CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt32>(SID_REPAIRPACKAGE), pUInt32Item->GetValue()); } @@ -1862,14 +1862,16 @@ void SdTiledRenderingTest::testDocumentRepair() int nView2 = SfxLokHelper::getView(); CPPUNIT_ASSERT(pView1 != pView2); { - std::unique_ptr<SfxPoolItem> pItem1; - std::unique_ptr<SfxPoolItem> pItem2; - pView1->GetViewFrame()->GetBindings().QueryState(SID_DOC_REPAIR, pItem1); - pView2->GetViewFrame()->GetBindings().QueryState(SID_DOC_REPAIR, pItem2); - CPPUNIT_ASSERT(dynamic_cast< const SfxBoolItem* >(pItem1.get())); - CPPUNIT_ASSERT(dynamic_cast< const SfxBoolItem* >(pItem2.get())); - CPPUNIT_ASSERT_EQUAL(false, dynamic_cast< const SfxBoolItem* >(pItem1.get())->GetValue()); - CPPUNIT_ASSERT_EQUAL(false, dynamic_cast< const SfxBoolItem* >(pItem2.get())->GetValue()); + std::unique_ptr<SfxPoolItem> xItem1; + std::unique_ptr<SfxPoolItem> xItem2; + pView1->GetViewFrame()->GetBindings().QueryState(SID_DOC_REPAIR, xItem1); + pView2->GetViewFrame()->GetBindings().QueryState(SID_DOC_REPAIR, xItem2); + const SfxBoolItem* pItem1 = dynamic_cast<const SfxBoolItem*>(xItem1.get()); + const SfxBoolItem* pItem2 = dynamic_cast<const SfxBoolItem*>(xItem2.get()); + CPPUNIT_ASSERT(pItem1); + CPPUNIT_ASSERT(pItem2); + CPPUNIT_ASSERT_EQUAL(false, pItem1->GetValue()); + CPPUNIT_ASSERT_EQUAL(false, pItem2->GetValue()); } // Insert a character in the second view. @@ -1881,14 +1883,16 @@ void SdTiledRenderingTest::testDocumentRepair() pXImpressDocument->postKeyEvent(LOK_KEYEVENT_KEYUP, 'c', 0); Scheduler::ProcessEventsToIdle(); { - std::unique_ptr<SfxPoolItem> pItem1; - std::unique_ptr<SfxPoolItem> pItem2; - pView1->GetViewFrame()->GetBindings().QueryState(SID_DOC_REPAIR, pItem1); - pView2->GetViewFrame()->GetBindings().QueryState(SID_DOC_REPAIR, pItem2); - CPPUNIT_ASSERT(dynamic_cast< const SfxBoolItem* >(pItem1.get())); - CPPUNIT_ASSERT(dynamic_cast< const SfxBoolItem* >(pItem2.get())); - CPPUNIT_ASSERT_EQUAL(true, dynamic_cast< const SfxBoolItem* >(pItem1.get())->GetValue()); - CPPUNIT_ASSERT_EQUAL(true, dynamic_cast< const SfxBoolItem* >(pItem2.get())->GetValue()); + std::unique_ptr<SfxPoolItem> xItem1; + std::unique_ptr<SfxPoolItem> xItem2; + pView1->GetViewFrame()->GetBindings().QueryState(SID_DOC_REPAIR, xItem1); + pView2->GetViewFrame()->GetBindings().QueryState(SID_DOC_REPAIR, xItem2); + const SfxBoolItem* pItem1 = dynamic_cast<const SfxBoolItem*>(xItem1.get()); + const SfxBoolItem* pItem2 = dynamic_cast<const SfxBoolItem*>(xItem2.get()); + CPPUNIT_ASSERT(pItem1); + CPPUNIT_ASSERT(pItem2); + CPPUNIT_ASSERT_EQUAL(true, pItem1->GetValue()); + CPPUNIT_ASSERT_EQUAL(true, pItem2->GetValue()); } comphelper::LibreOfficeKit::setActive(false); @@ -1903,12 +1907,12 @@ void SdTiledRenderingTest::testLanguageStatus() SfxLokHelper::createView(); SfxViewShell* pView2 = SfxViewShell::Current(); { - std::unique_ptr<SfxPoolItem> pItem1; - std::unique_ptr<SfxPoolItem> pItem2; - pView1->GetViewFrame()->GetBindings().QueryState(SID_LANGUAGE_STATUS, pItem1); - pView2->GetViewFrame()->GetBindings().QueryState(SID_LANGUAGE_STATUS, pItem2); - CPPUNIT_ASSERT(dynamic_cast< const SfxStringItem* >(pItem1.get())); - CPPUNIT_ASSERT(dynamic_cast< const SfxStringItem* >(pItem2.get())); + std::unique_ptr<SfxPoolItem> xItem1; + std::unique_ptr<SfxPoolItem> xItem2; + pView1->GetViewFrame()->GetBindings().QueryState(SID_LANGUAGE_STATUS, xItem1); + pView2->GetViewFrame()->GetBindings().QueryState(SID_LANGUAGE_STATUS, xItem2); + CPPUNIT_ASSERT(dynamic_cast< const SfxStringItem* >(xItem1.get())); + CPPUNIT_ASSERT(dynamic_cast< const SfxStringItem* >(xItem2.get())); } comphelper::LibreOfficeKit::setActive(false); @@ -1922,12 +1926,12 @@ void SdTiledRenderingTest::testDefaultView() SdXImpressDocument* pXImpressDocument = createDoc("notes-view.odp"); sd::ViewShell* pView = pXImpressDocument->GetDocShell()->GetViewShell(); { - std::unique_ptr<SfxPoolItem> pItem1; - std::unique_ptr<SfxPoolItem> pItem2; - pView->GetViewFrame()->GetBindings().QueryState(SID_NORMAL_MULTI_PANE_GUI, pItem1); - pView->GetViewFrame()->GetBindings().QueryState(SID_NOTES_MODE, pItem2); - const SfxBoolItem* pImpressView = dynamic_cast< const SfxBoolItem* >(pItem1.get()); - const SfxBoolItem* pNotesView = dynamic_cast< const SfxBoolItem* >(pItem2.get()); + std::unique_ptr<SfxPoolItem> xItem1; + std::unique_ptr<SfxPoolItem> xItem2; + pView->GetViewFrame()->GetBindings().QueryState(SID_NORMAL_MULTI_PANE_GUI, xItem1); + pView->GetViewFrame()->GetBindings().QueryState(SID_NOTES_MODE, xItem2); + const SfxBoolItem* pImpressView = dynamic_cast< const SfxBoolItem* >(xItem1.get()); + const SfxBoolItem* pNotesView = dynamic_cast< const SfxBoolItem* >(xItem2.get()); CPPUNIT_ASSERT(pImpressView); CPPUNIT_ASSERT(pNotesView); CPPUNIT_ASSERT_EQUAL(true, pImpressView->GetValue()); diff --git a/sw/qa/extras/tiledrendering/tiledrendering.cxx b/sw/qa/extras/tiledrendering/tiledrendering.cxx index 01a5e10eecbd..4bed2db8ed28 100644 --- a/sw/qa/extras/tiledrendering/tiledrendering.cxx +++ b/sw/qa/extras/tiledrendering/tiledrendering.cxx @@ -1907,14 +1907,16 @@ void SwTiledRenderingTest::testDocumentRepair() int nView2 = SfxLokHelper::getView(); CPPUNIT_ASSERT(pView1 != pView2); { - std::unique_ptr<SfxPoolItem> pItem1; - std::unique_ptr<SfxPoolItem> pItem2; - pView1->GetViewFrame()->GetBindings().QueryState(SID_DOC_REPAIR, pItem1); - pView2->GetViewFrame()->GetBindings().QueryState(SID_DOC_REPAIR, pItem2); - CPPUNIT_ASSERT(dynamic_cast< const SfxBoolItem* >(pItem1.get())); - CPPUNIT_ASSERT(dynamic_cast< const SfxBoolItem* >(pItem2.get())); - CPPUNIT_ASSERT_EQUAL(false, dynamic_cast< const SfxBoolItem* >(pItem1.get())->GetValue()); - CPPUNIT_ASSERT_EQUAL(false, dynamic_cast< const SfxBoolItem* >(pItem2.get())->GetValue()); + std::unique_ptr<SfxPoolItem> xItem1; + std::unique_ptr<SfxPoolItem> xItem2; + pView1->GetViewFrame()->GetBindings().QueryState(SID_DOC_REPAIR, xItem1); + pView2->GetViewFrame()->GetBindings().QueryState(SID_DOC_REPAIR, xItem2); + const SfxBoolItem* pItem1 = dynamic_cast<const SfxBoolItem*>(xItem1.get()); + const SfxBoolItem* pItem2 = dynamic_cast<const SfxBoolItem*>(xItem2.get()); + CPPUNIT_ASSERT(pItem1); + CPPUNIT_ASSERT(pItem2); + CPPUNIT_ASSERT_EQUAL(false, pItem1->GetValue()); + CPPUNIT_ASSERT_EQUAL(false, pItem2->GetValue()); } // Insert a character in the second view. @@ -1923,14 +1925,16 @@ void SwTiledRenderingTest::testDocumentRepair() pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYUP, 'u', 0); Scheduler::ProcessEventsToIdle(); { - std::unique_ptr<SfxPoolItem> pItem1; - std::unique_ptr<SfxPoolItem> pItem2; - pView1->GetViewFrame()->GetBindings().QueryState(SID_DOC_REPAIR, pItem1); - pView2->GetViewFrame()->GetBindings().QueryState(SID_DOC_REPAIR, pItem2); - CPPUNIT_ASSERT(dynamic_cast< const SfxBoolItem* >(pItem1.get())); - CPPUNIT_ASSERT(dynamic_cast< const SfxBoolItem* >(pItem2.get())); - CPPUNIT_ASSERT_EQUAL(true, dynamic_cast< const SfxBoolItem* >(pItem1.get())->GetValue()); - CPPUNIT_ASSERT_EQUAL(true, dynamic_cast< const SfxBoolItem* >(pItem2.get())->GetValue()); + std::unique_ptr<SfxPoolItem> xItem1; + std::unique_ptr<SfxPoolItem> xItem2; + pView1->GetViewFrame()->GetBindings().QueryState(SID_DOC_REPAIR, xItem1); + pView2->GetViewFrame()->GetBindings().QueryState(SID_DOC_REPAIR, xItem2); + const SfxBoolItem* pItem1 = dynamic_cast<const SfxBoolItem*>(xItem1.get()); + const SfxBoolItem* pItem2 = dynamic_cast<const SfxBoolItem*>(xItem2.get()); + CPPUNIT_ASSERT(pItem1); + CPPUNIT_ASSERT(pItem2); + CPPUNIT_ASSERT_EQUAL(true, pItem1->GetValue()); + CPPUNIT_ASSERT_EQUAL(true, pItem2->GetValue()); } comphelper::LibreOfficeKit::setActive(false); @@ -1942,8 +1946,9 @@ void checkPageHeaderOrFooter(const SfxViewShell* pViewShell, sal_uInt16 nWhich, { const SfxPoolItem* pState = nullptr; pViewShell->GetDispatcher()->QueryState(nWhich, pState); - CPPUNIT_ASSERT(dynamic_cast< const SfxBoolItem * >(pState)); - CPPUNIT_ASSERT_EQUAL(bValue, dynamic_cast< const SfxBoolItem * >(pState)->GetValue()); + const SfxBoolItem* pBoolItem = dynamic_cast<const SfxBoolItem*>(pState); + CPPUNIT_ASSERT(pBoolItem); + CPPUNIT_ASSERT_EQUAL(bValue, pBoolItem->GetValue()); }; } commit 77da600bf3f0b2279a21680169dc3136bdc2639c Author: Caolán McNamara <caol...@redhat.com> Date: Sat Dec 16 19:11:06 2017 +0000 coverity#1426167 refactor to be less obscure no logic change intended Change-Id: I10ef6038351b2808c2030aa55f05e078d80345ae Reviewed-on: https://gerrit.libreoffice.org/46609 Tested-by: Jenkins <c...@libreoffice.org> Reviewed-by: Caolán McNamara <caol...@redhat.com> Tested-by: Caolán McNamara <caol...@redhat.com> diff --git a/sw/source/core/layout/atrfrm.cxx b/sw/source/core/layout/atrfrm.cxx index 2b15de1ffcd3..0673acad36cf 100644 --- a/sw/source/core/layout/atrfrm.cxx +++ b/sw/source/core/layout/atrfrm.cxx @@ -2546,58 +2546,61 @@ bool SwFrameFormat::supportsFullDrawingLayerFillAttributeSet() const void SwFrameFormat::Modify( const SfxPoolItem* pOld, const SfxPoolItem* pNew ) { - SwFormatHeader const *pH = nullptr; - SwFormatFooter const *pF = nullptr; - - const sal_uInt16 nWhich = pNew ? pNew->Which() : 0; - - if( RES_ATTRSET_CHG == nWhich ) + if (pNew) { - static_cast<const SwAttrSetChg*>(pNew)->GetChgSet()->GetItemState( - RES_HEADER, false, reinterpret_cast<const SfxPoolItem**>(&pH) ); - static_cast<const SwAttrSetChg*>(pNew)->GetChgSet()->GetItemState( - RES_FOOTER, false, reinterpret_cast<const SfxPoolItem**>(&pF) ); + SwFormatHeader const *pH = nullptr; + SwFormatFooter const *pF = nullptr; + + const sal_uInt16 nWhich = pNew->Which(); - // reset fill information - if (maFillAttributes.get() && supportsFullDrawingLayerFillAttributeSet()) + if( RES_ATTRSET_CHG == nWhich ) { - SfxItemIter aIter(*static_cast<const SwAttrSetChg*>(pNew)->GetChgSet()); - bool bReset(false); + static_cast<const SwAttrSetChg*>(pNew)->GetChgSet()->GetItemState( + RES_HEADER, false, reinterpret_cast<const SfxPoolItem**>(&pH) ); + static_cast<const SwAttrSetChg*>(pNew)->GetChgSet()->GetItemState( + RES_FOOTER, false, reinterpret_cast<const SfxPoolItem**>(&pF) ); - for(const SfxPoolItem* pItem = aIter.FirstItem(); pItem && !bReset; pItem = aIter.NextItem()) + // reset fill information + if (maFillAttributes.get() && supportsFullDrawingLayerFillAttributeSet()) { - bReset = !IsInvalidItem(pItem) && pItem->Which() >= XATTR_FILL_FIRST && pItem->Which() <= XATTR_FILL_LAST; - } + SfxItemIter aIter(*static_cast<const SwAttrSetChg*>(pNew)->GetChgSet()); + bool bReset(false); - if(bReset) - { - maFillAttributes.reset(); + for(const SfxPoolItem* pItem = aIter.FirstItem(); pItem && !bReset; pItem = aIter.NextItem()) + { + bReset = !IsInvalidItem(pItem) && pItem->Which() >= XATTR_FILL_FIRST && pItem->Which() <= XATTR_FILL_LAST; + } + + if(bReset) + { + maFillAttributes.reset(); + } } } - } - else if(RES_FMT_CHG == nWhich) - { - // reset fill information on format change (e.g. style changed) - if (maFillAttributes.get() && supportsFullDrawingLayerFillAttributeSet()) + else if(RES_FMT_CHG == nWhich) { - maFillAttributes.reset(); + // reset fill information on format change (e.g. style changed) + if (maFillAttributes.get() && supportsFullDrawingLayerFillAttributeSet()) + { + maFillAttributes.reset(); + } } - } - else if( RES_HEADER == nWhich ) - pH = static_cast<const SwFormatHeader*>(pNew); - else if( RES_FOOTER == nWhich ) - pF = static_cast<const SwFormatFooter*>(pNew); + else if( RES_HEADER == nWhich ) + pH = static_cast<const SwFormatHeader*>(pNew); + else if( RES_FOOTER == nWhich ) + pF = static_cast<const SwFormatFooter*>(pNew); - if( pH && pH->IsActive() && !pH->GetHeaderFormat() ) - { //If he doesn't have one, I'll add one - SwFrameFormat *pFormat = GetDoc()->getIDocumentLayoutAccess().MakeLayoutFormat( RndStdIds::HEADER, nullptr ); - const_cast<SwFormatHeader *>(pH)->RegisterToFormat( *pFormat ); - } + if( pH && pH->IsActive() && !pH->GetHeaderFormat() ) + { //If he doesn't have one, I'll add one + SwFrameFormat *pFormat = GetDoc()->getIDocumentLayoutAccess().MakeLayoutFormat( RndStdIds::HEADER, nullptr ); + const_cast<SwFormatHeader *>(pH)->RegisterToFormat( *pFormat ); + } - if( pF && pF->IsActive() && !pF->GetFooterFormat() ) - { //If he doesn't have one, I'll add one - SwFrameFormat *pFormat = GetDoc()->getIDocumentLayoutAccess().MakeLayoutFormat( RndStdIds::FOOTER, nullptr ); - const_cast<SwFormatFooter *>(pF)->RegisterToFormat( *pFormat ); + if( pF && pF->IsActive() && !pF->GetFooterFormat() ) + { //If he doesn't have one, I'll add one + SwFrameFormat *pFormat = GetDoc()->getIDocumentLayoutAccess().MakeLayoutFormat( RndStdIds::FOOTER, nullptr ); + const_cast<SwFormatFooter *>(pF)->RegisterToFormat( *pFormat ); + } } SwFormat::Modify( pOld, pNew ); commit 9cca2ca9af012ff8f96699febba0dc860768ef3c Author: Caolán McNamara <caol...@redhat.com> Date: Sat Dec 16 19:17:44 2017 +0000 coverity#1426162 refactor to be more clear and help out coverity wrt 'Dereference after null check' Change-Id: I8c07fd0afc686e1c0bfd87d9c8bd1ea341f6e616 Reviewed-on: https://gerrit.libreoffice.org/46610 Tested-by: Jenkins <c...@libreoffice.org> Reviewed-by: Caolán McNamara <caol...@redhat.com> Tested-by: Caolán McNamara <caol...@redhat.com> diff --git a/sw/source/core/txtnode/ndtxt.cxx b/sw/source/core/txtnode/ndtxt.cxx index 49ada34c9920..83b68aae6f0b 100644 --- a/sw/source/core/txtnode/ndtxt.cxx +++ b/sw/source/core/txtnode/ndtxt.cxx @@ -3571,9 +3571,9 @@ void SwTextNode::Modify( const SfxPoolItem* pOldValue, const SfxPoolItem* pNewVa } // reset fill information - if(maFillAttributes.get()) + if (maFillAttributes.get() && pNewValue) { - const sal_uInt16 nWhich = pNewValue ? pNewValue->Which() : 0; + const sal_uInt16 nWhich = pNewValue->Which(); bool bReset(RES_FMT_CHG == nWhich); // ..on format change (e.g. style changed) if(!bReset && RES_ATTRSET_CHG == nWhich) // ..on ItemChange from DrawingLayer FillAttributes
_______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits