Date: prev next · Thread: first prev next last
2010 Archives by date, by thread · List index


Hi!

Here goes my first patch. It silences a "possible null pointer dereference" of
pPage (at the end of diff). Perhaps not for merging yet since my build has not
yet progressed far enough to see that it builds and works and I'd also like to
know what is the preferred way of handling warnings like this.

The issue here is that both pFact and fnCreatePage are checked for nullness
but if either of them is null then pPage would get dereferenced as null. So we
will crash here anyway if that is the case, the question is what is the best
way to handle it? With my patch the null pointer crash will happen at the
earliest possible location, but should I add ASSERT(pFact) and
ASSERT(fnCreatePage) to document that this is intentional?

Cppcheck also finds lots of places where a null pointer crash is done
intentionally for things like "impossible" switch-case values. Sometimes this
is quite well hidden like in sw/source/ui/fldui/fldedt.cxx:203

  pTabPage = SwFldDokPage::Create(this, *(SfxItemSet*)0);

and somewhere I remember also seeing ASSERT(!this). There should be some
standard way of saying "this should never be reached but if it does, just crash
here" but I couldn't find out what it is. Exceptions perhaps, but are those
allowed?

This and all my future patches to this list are licensed under LGPLv3+ unless I
note otherwise.

Harri


diff --git a/sw/source/ui/uiview/viewprt.cxx b/sw/source/ui/uiview/viewprt.cxx
index 88ad189..0f7aabd 100644
--- a/sw/source/ui/uiview/viewprt.cxx
+++ b/sw/source/ui/uiview/viewprt.cxx
@@ -320,16 +320,11 @@ void __EXPORT SwView::ExecutePrint(SfxRequest& rReq)
 
 SfxTabPage* CreatePrintOptionsPage( Window *pParent,
                                 const SfxItemSet &rOptions, BOOL bPreview )
 {
-    SfxTabPage* pPage = NULL;
     SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
-    if ( pFact )
-    {
-        ::CreateTabPage fnCreatePage = pFact->GetTabPageCreatorFunc( TP_OPTPRINT_PAGE );
-        if ( fnCreatePage )
-            pPage = (*fnCreatePage)( pParent, rOptions );
-    }
+    ::CreateTabPage fnCreatePage = pFact->GetTabPageCreatorFunc( TP_OPTPRINT_PAGE );
+    SfxTabPage* pPage = (*fnCreatePage)( pParent, rOptions );
     SfxAllItemSet aSet(*(rOptions.GetPool()));
     aSet.Put (SfxBoolItem(SID_PREVIEWFLAG_TYPE, bPreview));
     aSet.Put (SfxBoolItem(SID_FAX_LIST, sal_True));
     pPage->PageCreated(aSet);

Context


Privacy Policy | Impressum (Legal Info) | Copyright information: Unless otherwise specified, all text and images on this website are licensed under the Creative Commons Attribution-Share Alike 3.0 License. This does not include the source code of LibreOffice, which is licensed under the Mozilla Public License (MPLv2). "LibreOffice" and "The Document Foundation" are registered trademarks of their corresponding registered owners or are in actual use as trademarks in one or more countries. Their respective logos and icons are also subject to international copyright laws. Use thereof is explained in our trademark policy.