sal/osl/w32/nlsupport.cxx |    2 +-
 sal/osl/w32/process.cxx   |    1 +
 sal/osl/w32/procimpl.cxx  |    2 +-
 sal/osl/w32/profile.cxx   |    7 ++++---
 sal/osl/w32/socket.cxx    |   10 +++++-----
 sal/osl/w32/thread.cxx    |    6 +++---
 sal/osl/w32/time.cxx      |    3 ++-
 sal/rtl/bootstrap.cxx     |    6 +++---
 sal/rtl/byteseq.cxx       |    8 ++++----
 sal/rtl/hash.cxx          |    3 +++
 sal/rtl/string.cxx        |    6 +++---
 11 files changed, 30 insertions(+), 24 deletions(-)

New commits:
commit d25b88ca2b6f59ce9b43b5d2e37ac7b95f2489f1
Author:     Caolán McNamara <caolan.mcnam...@collabora.com>
AuthorDate: Tue Apr 30 09:22:17 2024 +0100
Commit:     Caolán McNamara <caolan.mcnam...@collabora.com>
CommitDate: Tue Apr 30 13:40:54 2024 +0200

    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.mcnam...@collabora.com>

diff --git a/sal/osl/w32/nlsupport.cxx b/sal/osl/w32/nlsupport.cxx
index 1c3648d5a09c..010a8f2f971a 100644
--- a/sal/osl/w32/nlsupport.cxx
+++ b/sal/osl/w32/nlsupport.cxx
@@ -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 */
diff --git a/sal/osl/w32/process.cxx b/sal/osl/w32/process.cxx
index 065415f2cf86..d18513be6dd5 100644
--- a/sal/osl/w32/process.cxx
+++ b/sal/osl/w32/process.cxx
@@ -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;
     }
diff --git a/sal/osl/w32/procimpl.cxx b/sal/osl/w32/procimpl.cxx
index a9a7b95cc2ce..173ca3e11651 100644
--- a/sal/osl/w32/procimpl.cxx
+++ b/sal/osl/w32/procimpl.cxx
@@ -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);
 
diff --git a/sal/osl/w32/profile.cxx b/sal/osl/w32/profile.cxx
index a0790c3de632..413171eab3e9 100644
--- a/sal/osl/w32/profile.cxx
+++ b/sal/osl/w32/profile.cxx
@@ -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;
     }
diff --git a/sal/osl/w32/socket.cxx b/sal/osl/w32/socket.cxx
index 07e4eb011202..bc5a50dfd99b 100644
--- a/sal/osl/w32/socket.cxx
+++ b/sal/osl/w32/socket.cxx
@@ -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;
diff --git a/sal/osl/w32/thread.cxx b/sal/osl/w32/thread.cxx
index 3640d43b9992..690431972516 100644
--- a/sal/osl/w32/thread.cxx
+++ b/sal/osl/w32/thread.cxx
@@ -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
diff --git a/sal/osl/w32/time.cxx b/sal/osl/w32/time.cxx
index 3f11746fedad..e8b2059f70d4 100644
--- a/sal/osl/w32/time.cxx
+++ b/sal/osl/w32/time.cxx
@@ -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 
= []()
     {
diff --git a/sal/rtl/bootstrap.cxx b/sal/rtl/bootstrap.cxx
index 754003e7a0e8..f5a650708057 100644
--- a/sal/rtl/bootstrap.cxx
+++ b/sal/rtl/bootstrap.cxx
@@ -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 == '\')
     {
diff --git a/sal/rtl/byteseq.cxx b/sal/rtl/byteseq.cxx
index 0084f3969812..5c9cb224178f 100644
--- a/sal/rtl/byteseq.cxx
+++ b/sal/rtl/byteseq.cxx
@@ -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 );
diff --git a/sal/rtl/hash.cxx b/sal/rtl/hash.cxx
index 4e255d965e17..ba7769d09a8c 100644
--- a/sal/rtl/hash.cxx
+++ b/sal/rtl/hash.cxx
@@ -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;
 }
diff --git a/sal/rtl/string.cxx b/sal/rtl/string.cxx
index 05f87475df0b..ce0e873fbd64 100644
--- a/sal/rtl/string.cxx
+++ b/sal/rtl/string.cxx
@@ -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;

Reply via email to