sc/source/ui/app/inputhdl.cxx    |    9 ++++++++-
 sc/source/ui/docshell/docsh5.cxx |    9 ++++++++-
 test/source/diff/diff.cxx        |    2 ++
 test/source/xmltesttools.cxx     |    6 ++++++
 4 files changed, 24 insertions(+), 2 deletions(-)

New commits:
commit 034eb5078096d146fb5c5e6246a407f2aad09094
Author:     Caolán McNamara <[email protected]>
AuthorDate: Sun May 12 12:52:14 2024 +0100
Commit:     Caolán McNamara <[email protected]>
CommitDate: Sun May 12 17:21:40 2024 +0200

    help msvc -analyzer out wrt C6011 Dereferencing NULL pointer
    
    Change-Id: Ied22e4ea805ab5a94f89a71438962bdd6d118771
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/167548
    Reviewed-by: Caolán McNamara <[email protected]>
    Tested-by: Jenkins

diff --git a/sc/source/ui/app/inputhdl.cxx b/sc/source/ui/app/inputhdl.cxx
index 6dd8315e7b4e..1c1aaf06963d 100644
--- a/sc/source/ui/app/inputhdl.cxx
+++ b/sc/source/ui/app/inputhdl.cxx
@@ -4227,6 +4227,13 @@ void ScInputHandler::InputCommand( const CommandEvent& 
rCEvt )
     }
 }
 
+static ScInputHdlState* getLastState(const ScInputHdlState* pState)
+{
+    if (!pState)
+        return nullptr;
+    return new ScInputHdlState(*pState);
+}
+
 void ScInputHandler::NotifyChange( const ScInputHdlState* pState,
                                    bool bForce, ScTabViewShell* pSourceSh,
                                    bool bStopEditing)
@@ -4260,7 +4267,7 @@ void ScInputHandler::NotifyChange( const ScInputHdlState* 
pState,
 
     if ( pState != pLastState.get() )
     {
-        pLastState.reset( pState ? new ScInputHdlState( *pState ) : nullptr);
+        pLastState.reset(getLastState(pState));
     }
 
     if ( pState && pActiveViewSh )
diff --git a/sc/source/ui/docshell/docsh5.cxx b/sc/source/ui/docshell/docsh5.cxx
index 63bb94408eba..1b2ddf216b9f 100644
--- a/sc/source/ui/docshell/docsh5.cxx
+++ b/sc/source/ui/docshell/docsh5.cxx
@@ -508,6 +508,13 @@ static OUString lcl_GetAreaName( ScDocument* pDoc, const 
ScArea* pArea )
     return aName;
 }
 
+static ScDBData* getUndoData(ScDBData* pDestData)
+{
+    if (!pDestData)
+        return nullptr;
+    return new ScDBData(*pDestData);
+}
+
 void ScDocShell::DoConsolidate( const ScConsolidateParam& rParam, bool bRecord 
)
 {
     ScConsData aData;
@@ -568,7 +575,7 @@ void ScDocShell::DoConsolidate( const ScConsolidateParam& 
rParam, bool bRecord )
     aData.GetSize( nColSize, nRowSize );
     if (bRecord && nColSize > 0 && nRowSize > 0)
     {
-        std::unique_ptr<ScDBData> pUndoData(pDestData ? new 
ScDBData(*pDestData) : nullptr);
+        std::unique_ptr<ScDBData> pUndoData(getUndoData(pDestData));
 
         SCTAB nDestTab = rParam.nTab;
         ScArea aDestArea( rParam.nTab, rParam.nCol, rParam.nRow,
commit 512e28bf8d10f9246df2d535f92c1ccef1628192
Author:     Caolán McNamara <[email protected]>
AuthorDate: Sun May 12 12:00:27 2024 +0100
Commit:     Caolán McNamara <[email protected]>
CommitDate: Sun May 12 17:21:32 2024 +0200

    WaE: C6011 Dereferencing NULL pointer warnings
    
    Change-Id: I7a4df11c23a92d0c5538cea4290dcc5e2c9ac3c3
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/167547
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <[email protected]>

diff --git a/test/source/diff/diff.cxx b/test/source/diff/diff.cxx
index 097452665308..dac6c1e4ed01 100644
--- a/test/source/diff/diff.cxx
+++ b/test/source/diff/diff.cxx
@@ -284,6 +284,8 @@ bool compareValuesWithTolerance(double val1, double val2, 
double tolerance, bool
 
 bool XMLDiff::compareAttributes(xmlNodePtr node1, xmlNodePtr node2)
 {
+    CPPUNIT_ASSERT(node1);
+    CPPUNIT_ASSERT(node2);
     xmlAttrPtr attr1 = nullptr;
     xmlAttrPtr attr2 = nullptr;
     for(attr1 = node1->properties, attr2 = node2->properties; attr1 != nullptr 
&& attr2 != nullptr; attr1 = attr1->next, attr2 = attr2->next)
diff --git a/test/source/xmltesttools.cxx b/test/source/xmltesttools.cxx
index b0e4cf48e989..22fa266a966d 100644
--- a/test/source/xmltesttools.cxx
+++ b/test/source/xmltesttools.cxx
@@ -92,6 +92,7 @@ OUString XmlTestTools::getXPath(const xmlDocUniquePtr& 
pXmlDoc, const OString& r
     xmlXPathObjectPtr pXmlObj = getXPathNode(pXmlDoc, rXPath);
     CPPUNIT_ASSERT(pXmlObj);
     xmlNodeSetPtr pXmlNodes = pXmlObj->nodesetval;
+    CPPUNIT_ASSERT(pXmlNodes);
     CPPUNIT_ASSERT_EQUAL_MESSAGE(OString(OString::Concat("In <") + 
pXmlDoc->name + ">, XPath '" + rXPath + "' number of nodes is 
incorrect").getStr(),
                                  1, xmlXPathNodeSetGetLength(pXmlNodes));
     CPPUNIT_ASSERT(!rAttribute.isEmpty());
@@ -240,6 +241,7 @@ void XmlTestTools::assertXPathChildren(const 
xmlDocUniquePtr& pXmlDoc, const OSt
 #if LIBXML_VERSION >= 20703 /* xmlChildElementCount is only available in 
libxml2 >= 2.7.3 */
     xmlXPathObjectPtr pXmlObj = getXPathNode(pXmlDoc, rXPath);
     xmlNodeSetPtr pXmlNodes = pXmlObj->nodesetval;
+    CPPUNIT_ASSERT(pXmlNodes);
     CPPUNIT_ASSERT_EQUAL_MESSAGE(OString(OString::Concat("In <") + 
pXmlDoc->name + ">, XPath '" + rXPath + "' number of nodes is 
incorrect").getStr(),
                                  1, xmlXPathNodeSetGetLength(pXmlNodes));
     xmlNodePtr pXmlNode = pXmlNodes->nodeTab[0];
@@ -257,6 +259,7 @@ void XmlTestTools::assertXPathNoAttribute(const 
xmlDocUniquePtr& pXmlDoc, const
 {
     xmlXPathObjectPtr pXmlObj = getXPathNode(pXmlDoc, rXPath);
     xmlNodeSetPtr pXmlNodes = pXmlObj->nodesetval;
+    CPPUNIT_ASSERT(pXmlNodes);
     CPPUNIT_ASSERT_EQUAL_MESSAGE(OString(OString::Concat("In <") + 
pXmlDoc->name + ">, XPath '" + rXPath + "' number of nodes is 
incorrect").getStr(),
                                  1, xmlXPathNodeSetGetLength(pXmlNodes));
     xmlNodePtr pXmlNode = pXmlNodes->nodeTab[0];
@@ -269,6 +272,7 @@ int XmlTestTools::getXPathPosition(const xmlDocUniquePtr& 
pXmlDoc, const OString
 {
     xmlXPathObjectPtr pXmlObj = getXPathNode(pXmlDoc, rXPath);
     xmlNodeSetPtr pXmlNodes = pXmlObj->nodesetval;
+    CPPUNIT_ASSERT(pXmlNodes);
     CPPUNIT_ASSERT_EQUAL_MESSAGE(OString(OString::Concat("In <") + 
pXmlDoc->name + ">, XPath '" + rXPath + "' number of nodes is 
incorrect").getStr(),
                                  1,
                                  xmlXPathNodeSetGetLength(pXmlNodes));
@@ -296,7 +300,9 @@ void XmlTestTools::assertXPathNodeName(const 
xmlDocUniquePtr& pXmlDoc, const OSt
                                           const OString& rExpectedName)
 {
     xmlXPathObjectPtr pXmlObj = getXPathNode(pXmlDoc, rXPath);
+    CPPUNIT_ASSERT(pXmlObj);
     xmlNodeSetPtr pXmlNodes = pXmlObj->nodesetval;
+    CPPUNIT_ASSERT(pXmlNodes);
     CPPUNIT_ASSERT_EQUAL_MESSAGE(OString(OString::Concat("In <") + 
pXmlDoc->name + ">, XPath '" + rXPath + "' number of nodes is 
incorrect").getStr(),
                                  1,
                                  xmlXPathNodeSetGetLength(pXmlNodes));

Reply via email to