From 42e38e671cd2866e876dcf4bfa5e01741a7104e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Caol=C3=A1n=20McNamara?= Date: Mon, 6 May 2024 11:29:17 +0100 Subject: [PATCH] WaE: C6011 Dereferencing NULL pointer warnings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I396bada76e47f5bccca8296e844822a564b1ea0a Reviewed-on: https://gerrit.libreoffice.org/c/core/+/167196 Tested-by: Jenkins Reviewed-by: Caolán McNamara --- connectivity/source/drivers/file/FNoException.cxx | 2 +- connectivity/source/drivers/file/FStatement.cxx | 10 +++++----- connectivity/source/drivers/file/fcomp.cxx | 6 +++--- .../source/drivers/firebird/PreparedStatement.cxx | 2 ++ .../source/drivers/firebird/StatementCommonBase.cxx | 2 ++ connectivity/source/drivers/odbc/ODatabaseMetaData.cxx | 2 +- connectivity/source/drivers/postgresql/pq_tools.cxx | 2 +- connectivity/source/inc/TConnection.hxx | 2 +- 8 files changed, 16 insertions(+), 12 deletions(-) diff --git a/connectivity/source/drivers/file/FNoException.cxx b/connectivity/source/drivers/file/FNoException.cxx index 920bb38859f1..c2cd9d9579d6 100644 --- a/connectivity/source/drivers/file/FNoException.cxx +++ b/connectivity/source/drivers/file/FNoException.cxx @@ -65,7 +65,7 @@ void OSQLAnalyzer::bindParameterRow(OValueRefRow const & _pRow) void OPreparedStatement::scanParameter(OSQLParseNode* pParseNode,std::vector< OSQLParseNode*>& _rParaNodes) { - DBG_ASSERT(pParseNode != nullptr,"OResultSet: internal error: invalid ParseNode"); + assert(pParseNode && "OResultSet: internal error: invalid ParseNode"); // found parameter Name-Rule? if (SQL_ISRULE(pParseNode,parameter)) diff --git a/connectivity/source/drivers/file/FStatement.cxx b/connectivity/source/drivers/file/FStatement.cxx index 4520abfeff1d..b6b4b8b125fc 100644 --- a/connectivity/source/drivers/file/FStatement.cxx +++ b/connectivity/source/drivers/file/FStatement.cxx @@ -576,7 +576,7 @@ void OStatement_Base::GetAssignValues() OSL_ENSURE(m_pParseTree->count() >= 4,"OResultSet: Error in Parse Tree"); OSQLParseNode * pAssignmentCommalist = m_pParseTree->getChild(3); - OSL_ENSURE(pAssignmentCommalist != nullptr,"OResultSet: pAssignmentCommalist == NULL"); + assert(pAssignmentCommalist && "OResultSet: pAssignmentCommalist == NULL"); OSL_ENSURE(SQL_ISRULE(pAssignmentCommalist,assignment_commalist),"OResultSet: Error in Parse Tree"); OSL_ENSURE(pAssignmentCommalist->count() > 0,"OResultSet: pAssignmentCommalist->count() <= 0"); @@ -585,15 +585,15 @@ void OStatement_Base::GetAssignValues() for (size_t i = 0; i < pAssignmentCommalist->count(); i++) { OSQLParseNode * pAssignment = pAssignmentCommalist->getChild(i); - OSL_ENSURE(pAssignment != nullptr,"OResultSet: pAssignment == NULL"); + assert(pAssignment && "OResultSet: pAssignment == NULL"); OSL_ENSURE(SQL_ISRULE(pAssignment,assignment),"OResultSet: Error in Parse Tree"); OSL_ENSURE(pAssignment->count() == 3,"OResultSet: pAssignment->count() != 3"); OSQLParseNode * pCol = pAssignment->getChild(0); - OSL_ENSURE(pCol != nullptr,"OResultSet: pCol == NULL"); + assert(pCol && "OResultSet: pCol == NULL"); OSQLParseNode * pComp = pAssignment->getChild(1); - OSL_ENSURE(pComp != nullptr,"OResultSet: pComp == NULL"); + assert(pComp && "OResultSet: pComp == NULL"); OSL_ENSURE(pComp->getNodeType() == SQLNodeType::Equal,"OResultSet: pComp->getNodeType() != SQLNodeType::Comparison"); if (pComp->getTokenValue().toChar() != '=') { @@ -614,7 +614,7 @@ void OStatement_Base::ParseAssignValues(const std::vector< OUString>& aColumnNam OSL_ENSURE(o3tl::make_unsigned(nIndex) <= aColumnNameList.size(),"SdbFileCursor::ParseAssignValues: nIndex > aColumnNameList.GetTokenCount()"); OUString aColumnName(aColumnNameList[nIndex]); OSL_ENSURE(aColumnName.getLength() > 0,"OResultSet: Column-Name not found"); - OSL_ENSURE(pRow_Value_Constructor_Elem != nullptr,"OResultSet: pRow_Value_Constructor_Elem must not be NULL!"); + assert(pRow_Value_Constructor_Elem != nullptr && "OResultSet: pRow_Value_Constructor_Elem must not be NULL!"); if (pRow_Value_Constructor_Elem->getNodeType() == SQLNodeType::String || pRow_Value_Constructor_Elem->getNodeType() == SQLNodeType::IntNum || diff --git a/connectivity/source/drivers/file/fcomp.cxx b/connectivity/source/drivers/file/fcomp.cxx index 45c9022340a9..a00de03eeb3a 100644 --- a/connectivity/source/drivers/file/fcomp.cxx +++ b/connectivity/source/drivers/file/fcomp.cxx @@ -75,7 +75,7 @@ void OPredicateCompiler::start(OSQLParseNode const * pSQLParseNode) DBG_ASSERT(pSQLParseNode->count() >= 4,"OFILECursor: Error in Parse Tree"); OSQLParseNode * pTableExp = pSQLParseNode->getChild(3); - DBG_ASSERT(pTableExp != nullptr,"Error in Parse Tree"); + assert(pTableExp && "Error in Parse Tree"); DBG_ASSERT(SQL_ISRULE(pTableExp,table_exp)," Error in Parse Tree"); DBG_ASSERT(pTableExp->count() == TABLE_EXPRESSION_CHILD_COUNT,"Error in Parse Tree"); @@ -546,7 +546,7 @@ bool OPredicateInterpreter::evaluate(OCodeList& rCodeList) m_aStack.pop(); DBG_ASSERT(m_aStack.empty(), "Stack error"); - DBG_ASSERT(pOperand, "Stack error"); + assert(pOperand && "Stack error"); const bool bResult = pOperand->isValid(); if (typeid(OOperandResult) == typeid(*pOperand)) @@ -572,7 +572,7 @@ void OPredicateInterpreter::evaluateSelection(OCodeList& rCodeList, ORowSetValue m_aStack.pop(); DBG_ASSERT(m_aStack.empty(), "Stack error"); - DBG_ASSERT(pOperand, "Stack error"); + assert(pOperand && "Stack error"); (*_rVal) = pOperand->getValue(); if (typeid(OOperandResult) == typeid(*pOperand)) diff --git a/connectivity/source/drivers/firebird/PreparedStatement.cxx b/connectivity/source/drivers/firebird/PreparedStatement.cxx index 35847d021ea0..cc162060aaf9 100644 --- a/connectivity/source/drivers/firebird/PreparedStatement.cxx +++ b/connectivity/source/drivers/firebird/PreparedStatement.cxx @@ -77,6 +77,7 @@ void OPreparedStatement::ensurePrepared() if (!m_pInSqlda) { m_pInSqlda = static_cast(calloc(1, XSQLDA_LENGTH(10))); + assert(m_pInSqlda && "Don't handle OOM conditions"); m_pInSqlda->version = SQLDA_VERSION1; m_pInSqlda->sqln = 10; } @@ -97,6 +98,7 @@ void OPreparedStatement::ensurePrepared() short nItems = m_pInSqlda->sqld; free(m_pInSqlda); m_pInSqlda = static_cast(calloc(1, XSQLDA_LENGTH(nItems))); + assert(m_pInSqlda && "Don't handle OOM conditions"); m_pInSqlda->version = SQLDA_VERSION1; m_pInSqlda->sqln = nItems; aErr = isc_dsql_describe_bind(m_statusVector, diff --git a/connectivity/source/drivers/firebird/StatementCommonBase.cxx b/connectivity/source/drivers/firebird/StatementCommonBase.cxx index 29ef5925657d..096c0ce436bd 100644 --- a/connectivity/source/drivers/firebird/StatementCommonBase.cxx +++ b/connectivity/source/drivers/firebird/StatementCommonBase.cxx @@ -131,6 +131,7 @@ void OStatementCommonBase::prepareAndDescribeStatement(std::u16string_view sql, if (!pOutSqlda) { pOutSqlda = static_cast(calloc(1, XSQLDA_LENGTH(10))); + assert(pOutSqlda && "Don't handle OOM conditions"); pOutSqlda->version = SQLDA_VERSION1; pOutSqlda->sqln = 10; } @@ -169,6 +170,7 @@ void OStatementCommonBase::prepareAndDescribeStatement(std::u16string_view sql, int n = pOutSqlda->sqld; free(pOutSqlda); pOutSqlda = static_cast(calloc(1, XSQLDA_LENGTH(n))); + assert(pOutSqlda && "Don't handle OOM conditions"); pOutSqlda->version = SQLDA_VERSION1; pOutSqlda->sqln = n; aErr = isc_dsql_describe(m_statusVector, diff --git a/connectivity/source/drivers/odbc/ODatabaseMetaData.cxx b/connectivity/source/drivers/odbc/ODatabaseMetaData.cxx index bd721d60a617..97cd0b1b33d9 100644 --- a/connectivity/source/drivers/odbc/ODatabaseMetaData.cxx +++ b/connectivity/source/drivers/odbc/ODatabaseMetaData.cxx @@ -40,7 +40,7 @@ ODatabaseMetaData::ODatabaseMetaData(const SQLHANDLE _pHandle,OConnection* _pCon ,m_pConnection(_pCon) ,m_bUseCatalog(true) { - OSL_ENSURE(m_pConnection,"ODatabaseMetaData::ODatabaseMetaData: No connection set!"); + assert(m_pConnection && "ODatabaseMetaData::ODatabaseMetaData: No connection set!"); if(!m_pConnection->isCatalogUsed()) { osl_atomic_increment( &m_refCount ); diff --git a/connectivity/source/drivers/postgresql/pq_tools.cxx b/connectivity/source/drivers/postgresql/pq_tools.cxx index fb42f864f97e..f2ed8a6574ae 100644 --- a/connectivity/source/drivers/postgresql/pq_tools.cxx +++ b/connectivity/source/drivers/postgresql/pq_tools.cxx @@ -154,7 +154,7 @@ void bufferQuoteAnyConstant( OUStringBuffer & buf, const Any &val, ConnectionSet static void ibufferQuoteIdentifier( OUStringBuffer & buf, std::u16string_view toQuote, ConnectionSettings *settings ) { - OSL_ENSURE(settings, "pgsql-sdbc: bufferQuoteIdentifier got NULL settings"); + assert(settings && "pgsql-sdbc: bufferQuoteIdentifier got NULL settings"); OString y = iOUStringToOString( toQuote, settings ); char *cstr = PQescapeIdentifier(settings->pConnection, y.getStr(), y.getLength()); diff --git a/connectivity/source/inc/TConnection.hxx b/connectivity/source/inc/TConnection.hxx index 2dbe2ef6a756..d68371315fd1 100644 --- a/connectivity/source/inc/TConnection.hxx +++ b/connectivity/source/inc/TConnection.hxx @@ -61,7 +61,7 @@ namespace connectivity rtl_TextEncoding getTextEncoding() const { return m_nTextEncoding; } const OUString& getURL() const { return m_sURL; } void setURL(const OUString& _rsUrl) { m_sURL = _rsUrl; } - void throwGenericSQLException(TranslateId pErrorResourceId, const css::uno::Reference< css::uno::XInterface>& _xContext); + [[noreturn]] void throwGenericSQLException(TranslateId pErrorResourceId, const css::uno::Reference< css::uno::XInterface>& _xContext); const SharedResources& getResources() const { return m_aResources;} void setConnectionInfo(const css::uno::Sequence< css::beans::PropertyValue >& _aInfo) { m_aConnectionInfo = _aInfo; }