WaE: C6011 Dereferencing NULL pointer warnings from unchecked malloc

upgrade OSL_ASSERT to assert and add a few more

Change-Id: Ib52ca573d9e0878fef94dec40410f71bc94dea04
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/166914
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolan.mcnamara@collabora.com>
This commit is contained in:
Caolán McNamara 2024-04-30 09:22:17 +01:00
parent 51407b6f8d
commit d25b88ca2b
11 changed files with 30 additions and 24 deletions

View File

@ -87,7 +87,7 @@ void imp_getProcessLocale( rtl_Locale ** ppLocale )
WCHAR langCode[ELP_LANGUAGE_FIELD_LENGTH];
WCHAR ctryCode[ELP_COUNTRY_FIELD_LENGTH];
OSL_ASSERT( ppLocale );
assert(ppLocale);
/* get the locale name to retrieve information from */
/* and call GetLocaleInfo to retrieve the iso codes */

View File

@ -149,6 +149,7 @@ oslProcess SAL_CALL osl_getProcess(oslProcessIdentifier Ident)
if (hProcess)
{
pProcImpl = static_cast< oslProcessImpl*>( malloc(sizeof(oslProcessImpl)) );
assert(pProcImpl && "Don't handle OOM conditions");
pProcImpl->m_hProcess = hProcess;
pProcImpl->m_IdProcess = Ident;
}

View File

@ -122,7 +122,7 @@ namespace /* private */
sal_uInt32 env_vars_count,
/*in|out*/ std::vector<OUString>* merged_env)
{
OSL_ASSERT(env_vars && env_vars_count > 0 && merged_env);
assert(env_vars && env_vars_count > 0 && merged_env);
read_environment(merged_env);

View File

@ -371,7 +371,7 @@ DWORD GetPrivateProfileStringWrapper(const osl_TProfileImpl* pProfile,
char* pszString, sal_uInt32 MaxLen,
const char* pszDefault)
{
OSL_ASSERT(pProfile && (!MaxLen || pszString));
assert(pProfile && (!MaxLen || pszString));
rtl_uString *pSection = nullptr, *pEntry = nullptr, *pDefault = nullptr;
if (pszSection)
@ -412,10 +412,10 @@ bool WritePrivateProfileStringWrapper(const osl_TProfileImpl* pProfile,
const char* pszSection, const char* pszEntry,
const char* pszString)
{
OSL_ASSERT(pProfile && pszSection);
assert(pProfile && pszSection);
rtl_uString *pSection, *pEntry = nullptr, *pString = nullptr;
rtl_string2UString(&pSection, pszSection, strlen(pszSection), osl_getThreadTextEncoding(), OSTRING_TO_OUSTRING_CVTFLAGS);
OSL_ASSERT(pSection);
assert(pSection);
if (pszEntry)
{
rtl_string2UString(&pEntry, pszEntry, strlen(pszEntry), osl_getThreadTextEncoding(), OSTRING_TO_OUSTRING_CVTFLAGS);
@ -1258,6 +1258,7 @@ static bool putLine(osl_TFile* pFile, const char *pszLine)
if ( pFile->m_pWriteBuf == nullptr )
{
pFile->m_pWriteBuf = static_cast<char*>(malloc(Len+3));
assert(pFile->m_pWriteBuf && "Don't handle OOM conditions");
pFile->m_nWriteBufLen = Len+3;
pFile->m_nWriteBufFree = Len+3;
}

View File

@ -329,13 +329,13 @@ oslSocketAddr SAL_CALL osl_copySocketAddr(oslSocketAddr Addr)
sal_Bool SAL_CALL osl_isEqualSocketAddr(oslSocketAddr Addr1, oslSocketAddr Addr2)
{
OSL_ASSERT(Addr1);
OSL_ASSERT(Addr2);
assert(Addr1);
assert(Addr2);
struct sockaddr* pAddr1= &(Addr1->m_sockaddr);
struct sockaddr* pAddr2= &(Addr2->m_sockaddr);
OSL_ASSERT(pAddr1);
OSL_ASSERT(pAddr2);
assert(pAddr1);
assert(pAddr2);
if (pAddr1->sa_family == pAddr2->sa_family)
{
@ -868,7 +868,7 @@ oslSocketAddr SAL_CALL osl_getPeerAddrOfSocket(oslSocket pSocket)
sal_Bool SAL_CALL osl_bindAddrToSocket ( oslSocket pSocket, oslSocketAddr pAddr)
{
OSL_ASSERT( pAddr );
assert(pAddr);
if (pSocket == nullptr) /* ENOTSOCK */
return false;

View File

@ -152,7 +152,7 @@ void SAL_CALL osl_resumeThread(oslThread Thread)
{
osl_TThreadImpl* pThreadImpl= static_cast<osl_TThreadImpl*>(Thread);
OSL_ASSERT(pThreadImpl); /* valid ptr? */
assert(pThreadImpl); /* valid ptr? */
ResumeThread(pThreadImpl->m_hThread);
}
@ -161,7 +161,7 @@ void SAL_CALL osl_suspendThread(oslThread Thread)
{
osl_TThreadImpl* pThreadImpl= static_cast<osl_TThreadImpl*>(Thread);
OSL_ASSERT(pThreadImpl); /* valid ptr? */
assert(pThreadImpl); /* valid ptr? */
SuspendThread(pThreadImpl->m_hThread);
}
@ -172,7 +172,7 @@ void SAL_CALL osl_setThreadPriority(oslThread Thread,
int winPriority;
osl_TThreadImpl* pThreadImpl= static_cast<osl_TThreadImpl*>(Thread);
OSL_ASSERT(pThreadImpl); /* valid ptr? */
assert(pThreadImpl); /* valid ptr? */
/* map enum to WIN32 levels
it would be faster and more elegant to preset

View File

@ -18,6 +18,7 @@
*/
#include <sal/config.h>
#include "assert.h"
#include "system.h"
#include "filetime.hxx"
@ -33,7 +34,7 @@ sal_Bool SAL_CALL osl_getSystemTime(TimeValue* pTimeVal)
typedef VOID (WINAPI *GetSystemTimePreciseAsFileTime_PROC)(LPFILETIME);
OSL_ASSERT(pTimeVal != nullptr);
assert(pTimeVal != nullptr);
static GetSystemTimePreciseAsFileTime_PROC pGetSystemTimePreciseAsFileTime = []()
{

View File

@ -72,7 +72,7 @@ bool isPathnameUrl(std::u16string_view url)
bool resolvePathnameUrl(OUString * url)
{
OSL_ASSERT(url);
assert(url);
if (!isPathnameUrl(*url) ||
(osl::FileBase::getFileURLFromSystemPath(
url->copy(VND_SUN_STAR_PATHNAME.size()), *url) ==
@ -835,7 +835,7 @@ void SAL_CALL rtl_bootstrap_expandMacros(rtl_uString ** macro)
void rtl_bootstrap_encode(rtl_uString const * value, rtl_uString ** encoded)
{
OSL_ASSERT(value);
assert(value);
OUStringBuffer b(value->length+5);
for (sal_Int32 i = 0; i < value->length; ++i)
{
@ -861,7 +861,7 @@ int hex(sal_Unicode c)
sal_Unicode read(std::u16string_view text, std::size_t * pos, bool * escaped)
{
OSL_ASSERT(pos && *pos < text.length() && escaped);
assert(pos && *pos < text.length() && escaped);
sal_Unicode c = text[(*pos)++];
if (c == '\\')
{

View File

@ -41,7 +41,7 @@ void SAL_CALL rtl_byte_sequence_reference2One(
{
sal_Sequence * pSequence;
OSL_ENSURE( ppSequence, "### null ptr!" );
assert(ppSequence && "### null ptr!");
pSequence = *ppSequence;
if (pSequence->nRefCount > 1)
@ -132,7 +132,7 @@ void SAL_CALL rtl_byte_sequence_realloc(
void SAL_CALL rtl_byte_sequence_acquire( sal_Sequence *pSequence )
SAL_THROW_EXTERN_C()
{
OSL_ASSERT( pSequence );
assert(pSequence);
osl_atomic_increment( &(pSequence->nRefCount) );
}
@ -151,7 +151,7 @@ void SAL_CALL rtl_byte_sequence_release( sal_Sequence *pSequence )
void SAL_CALL rtl_byte_sequence_construct( sal_Sequence **ppSequence , sal_Int32 nLength )
SAL_THROW_EXTERN_C()
{
OSL_ASSERT( ppSequence );
assert(ppSequence);
if( *ppSequence )
{
rtl_byte_sequence_release( *ppSequence );
@ -178,7 +178,7 @@ void SAL_CALL rtl_byte_sequence_construct( sal_Sequence **ppSequence , sal_Int32
void SAL_CALL rtl_byte_sequence_constructNoDefault( sal_Sequence **ppSequence , sal_Int32 nLength )
SAL_THROW_EXTERN_C()
{
OSL_ASSERT( ppSequence );
assert(ppSequence);
if( *ppSequence )
{
rtl_byte_sequence_release( *ppSequence );

View File

@ -19,6 +19,7 @@
#include <sal/config.h>
#include <assert.h>
#include <stdlib.h>
#include "hash.hxx"
@ -76,10 +77,12 @@ static sal_uInt32 hashString(rtl_uString *pString)
static StringHashTable * rtl_str_hash_new(sal_uInt32 nSize)
{
StringHashTable *pHash = static_cast<StringHashTable *>(malloc(sizeof(StringHashTable)));
assert(pHash && "Don't handle OOM conditions");
pHash->nEntries = 0;
pHash->nSize = getNextSize (nSize);
pHash->pData = static_cast< rtl_uString ** >(calloc(pHash->nSize, sizeof(rtl_uString *)));
assert(pHash->pData && "Don't handle OOM conditions");
return pHash;
}

View File

@ -161,7 +161,7 @@ static bool rtl_impl_convertUStringToString(rtl_String ** pTarget,
if ( *pTarget )
rtl_string_release( *pTarget );
*pTarget = rtl_string_ImplAlloc( nLength );
OSL_ASSERT(*pTarget != nullptr);
assert(*pTarget != nullptr);
pBuffer = (*pTarget)->buffer;
do
{
@ -200,7 +200,7 @@ static bool rtl_impl_convertUStringToString(rtl_String ** pTarget,
for (;;)
{
pTemp = rtl_string_ImplAlloc( nNewLen );
OSL_ASSERT(pTemp != nullptr);
assert(pTemp != nullptr);
nDestBytes = rtl_convertUnicodeToText( hConverter, nullptr,
pSource, nLength,
pTemp->buffer, nNewLen,
@ -230,7 +230,7 @@ static bool rtl_impl_convertUStringToString(rtl_String ** pTarget,
if ( nNewLen > nDestBytes+8 )
{
rtl_String* pTemp2 = rtl_string_ImplAlloc( nDestBytes );
OSL_ASSERT(pTemp2 != nullptr);
assert(pTemp2 != nullptr);
rtl::str::Copy(pTemp2->buffer, pTemp->buffer, nDestBytes);
rtl_freeString( pTemp );
pTemp = pTemp2;