tdf#120703 PVS: Silence V575 warnings
V575 The potential null pointer is passed into 'foo' function
Add asserts to those cases that are related to OOM cases. There's
nothing to be done if the assertions fail anyway.
Change-Id: I92ac95d44f512aa1948b1552b0e1f6da695a9f92
Reviewed-on: https://gerrit.libreoffice.org/70008
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index dfbbdd8..ba77d5a 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -2239,6 +2239,7 @@
OString aString = OUStringToOString(aPartInfo, RTL_TEXTENCODING_UTF8);
char* pMemory = static_cast<char*>(malloc(aString.getLength() + 1));
assert(pMemory); // Don't handle OOM conditions
strcpy(pMemory, aString.getStr());
return pMemory;
}
@@ -2259,6 +2260,7 @@
OUString sRectangles = pDoc->getPartPageRectangles();
OString aString = OUStringToOString(sRectangles, RTL_TEXTENCODING_UTF8);
char* pMemory = static_cast<char*>(malloc(aString.getLength() + 1));
assert(pMemory); // Don't handle OOM conditions
strcpy(pMemory, aString.getStr());
return pMemory;
@@ -2280,6 +2282,7 @@
OUString sName = pDoc->getPartName( nPart );
OString aString = OUStringToOString(sName, RTL_TEXTENCODING_UTF8);
char* pMemory = static_cast<char*>(malloc(aString.getLength() + 1));
assert(pMemory); // Don't handle OOM conditions
strcpy(pMemory, aString.getStr());
return pMemory;
@@ -2301,6 +2304,7 @@
OUString sHash = pDoc->getPartHash(nPart);
OString aString = OUStringToOString(sHash, RTL_TEXTENCODING_UTF8);
char* pMemory = static_cast<char*>(malloc(aString.getLength() + 1));
assert(pMemory); // Don't handle OOM conditions
strcpy(pMemory, aString.getStr());
return pMemory;
@@ -3100,6 +3104,7 @@
aRet = pDoc->getTextSelection("text/plain;charset=utf-8", aUsedMimeType);
char* pMemory = static_cast<char*>(malloc(aRet.getLength() + 1));
assert(pMemory); // Don't handle OOM conditions
strcpy(pMemory, aRet.getStr());
if (pUsedMimeType)
@@ -3215,6 +3220,7 @@
std::stringstream aStream;
boost::property_tree::write_json(aStream, aTree);
char* pJson = static_cast<char*>(malloc(aStream.str().size() + 1));
assert(pJson); // Don't handle OOM conditions
strcpy(pJson, aStream.str().c_str());
pJson[aStream.str().size()] = '\0';
return pJson;
@@ -3253,6 +3259,7 @@
std::stringstream aStream;
boost::property_tree::write_json(aStream, aTree);
char* pJson = static_cast<char*>(malloc(aStream.str().size() + 1));
assert(pJson); // Don't handle OOM conditions
strcpy(pJson, aStream.str().c_str());
pJson[aStream.str().size()] = '\0';
return pJson;
@@ -3305,6 +3312,7 @@
std::stringstream aStream;
boost::property_tree::write_json(aStream, aTree);
char* pJson = static_cast<char*>(malloc(aStream.str().size() + 1));
assert(pJson); // Don't handle OOM conditions
strcpy(pJson, aStream.str().c_str());
pJson[aStream.str().size()] = '\0';
return pJson;
@@ -3429,6 +3437,7 @@
std::stringstream aStream;
boost::property_tree::write_json(aStream, aTree);
char* pJson = static_cast<char*>(malloc(aStream.str().size() + 1));
assert(pJson); // Don't handle OOM conditions
strcpy(pJson, aStream.str().c_str());
pJson[aStream.str().size()] = '\0';
return pJson;
@@ -3650,6 +3659,7 @@
OString aString = OUStringToOString(aHeaders, RTL_TEXTENCODING_UTF8);
char* pMemory = static_cast<char*>(malloc(aString.getLength() + 1));
assert(pMemory); // Don't handle OOM conditions
strcpy(pMemory, aString.getStr());
return pMemory;
}
@@ -3701,6 +3711,7 @@
OString aString = pDoc->getCellCursor(nOutputWidth, nOutputHeight, nTileWidth, nTileHeight);
char* pMemory = static_cast<char*>(malloc(aString.getLength() + 1));
assert(pMemory); // Don't handle OOM conditions
strcpy(pMemory, aString.getStr());
return pMemory;
}
@@ -4194,6 +4205,7 @@
LibLibreOffice_Impl* pLib = static_cast<LibLibreOffice_Impl*>(pThis);
OString aString = OUStringToOString(pLib->maLastExceptionMsg, RTL_TEXTENCODING_UTF8);
char* pMemory = static_cast<char*>(malloc(aString.getLength() + 1));
assert(pMemory); // Don't handle OOM conditions
strcpy(pMemory, aString.getStr());
return pMemory;
}
@@ -4290,6 +4302,7 @@
const OString sVersionStr = OUStringToOString(ReplaceStringHookProc(sVersionStrTemplate), RTL_TEXTENCODING_UTF8);
char* pVersion = static_cast<char*>(malloc(sVersionStr.getLength() + 1));
assert(pVersion); // Don't handle OOM conditions
strcpy(pVersion, sVersionStr.getStr());
return pVersion;
}
diff --git a/jvmfwk/plugins/sunmajor/pluginlib/sunjavaplugin.cxx b/jvmfwk/plugins/sunmajor/pluginlib/sunjavaplugin.cxx
index 6949ed9..b2cc8ed 100644
--- a/jvmfwk/plugins/sunmajor/pluginlib/sunjavaplugin.cxx
+++ b/jvmfwk/plugins/sunmajor/pluginlib/sunjavaplugin.cxx
@@ -528,7 +528,7 @@
}
PIMAGE_DOS_HEADER dos_hdr = static_cast<PIMAGE_DOS_HEADER>(malloc(st.st_size));
assert(dos_hdr);
if (fread(dos_hdr, st.st_size, 1, f) != 1 ||
memcmp(dos_hdr, "MZ", 2) != 0 ||
dos_hdr->e_lfanew < 0 ||
diff --git a/odk/source/unoapploader/win/unoapploader.c b/odk/source/unoapploader/win/unoapploader.c
index dd5cfaf..455f468 100644
--- a/odk/source/unoapploader/win/unoapploader.c
+++ b/odk/source/unoapploader/win/unoapploader.c
@@ -17,6 +17,7 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
@@ -208,6 +209,7 @@
if ( value != NULL )
size += wcslen( PATHSEPARATOR ) + wcslen( value );
wchar_t* envstr = (wchar_t*) malloc( size*sizeof(wchar_t) );
assert(envstr);
wcscpy( envstr, ENVVARNAME );
wcscat( envstr, L"=" );
wcscat( envstr, path );
@@ -312,6 +314,7 @@
/* create the command line */
cmdline = (wchar_t*) malloc( (wcslen( DQUOTE ) + wcslen( cmdname ) +
wcslen ( DQUOTE ) + wcslen( SPACE ) + wcslen( appendix ) + 1) * sizeof(wchar_t) );
assert(cmdline);
wcscpy( cmdline, DQUOTE );
wcscat( cmdline, cmdname );
wcscat( cmdline, DQUOTE );
diff --git a/sal/osl/w32/file_dirvol.cxx b/sal/osl/w32/file_dirvol.cxx
index cfdf957..36a4b5d 100644
--- a/sal/osl/w32/file_dirvol.cxx
+++ b/sal/osl/w32/file_dirvol.cxx
@@ -345,11 +345,12 @@
}
WCHAR* szFileMask = static_cast< WCHAR* >( malloc( sizeof( WCHAR ) * ( nLen + nSuffLen + 1 ) ) );
assert(szFileMask); // Don't handle OOM conditions
wcscpy( szFileMask, o3tl::toW(rtl_uString_getStr( pPath )) );
wcscat( szFileMask, pSuffix );
pDirectory = static_cast<LPDIRECTORY>(HeapAlloc(GetProcessHeap(), 0, sizeof(DIRECTORY)));
assert(pDirectory); // Don't handle OOM conditions
pDirectory->hFind = FindFirstFileW(szFileMask, &pDirectory->aFirstData);
if (!IsValidHandle(pDirectory->hFind))
@@ -437,6 +438,7 @@
Directory_Impl *pDirImpl;
pDirImpl = static_cast<Directory_Impl*>(malloc( sizeof(Directory_Impl)));
assert(pDirImpl); // Don't handle OOM conditions
ZeroMemory( pDirImpl, sizeof(Directory_Impl) );
rtl_uString_newFromString( &pDirImpl->m_pDirectoryPath, strSysPath );
@@ -501,6 +503,7 @@
*pDirectory = nullptr;
Directory_Impl *pDirImpl = static_cast<Directory_Impl*>(malloc(sizeof(Directory_Impl)));
assert(pDirImpl); // Don't handle OOM conditions
ZeroMemory( pDirImpl, sizeof(Directory_Impl) );
rtl_uString_newFromString( &pDirImpl->m_pDirectoryPath, strDirectoryPath );
@@ -566,6 +569,7 @@
Directory_Impl *pDirImpl;
pDirImpl = static_cast<Directory_Impl*>(malloc(sizeof(Directory_Impl)));
assert(pDirImpl); // Don't handle OOM conditions
ZeroMemory( pDirImpl, sizeof(Directory_Impl) );
pDirImpl->uType = DIRECTORYTYPE_NETROOT;
pDirImpl->hDirectory = hEnum;
@@ -1068,18 +1072,24 @@
{
DirectoryItem_Impl *pItemImpl =
static_cast<DirectoryItem_Impl*>(malloc(sizeof(DirectoryItem_Impl)));
if (!pItemImpl)
error = osl_File_E_NOMEM;
ZeroMemory( pItemImpl, sizeof(DirectoryItem_Impl) );
osl_acquireDirectoryItem( static_cast<oslDirectoryItem>(pItemImpl) );
if (osl_File_E_None == error)
{
ZeroMemory(pItemImpl, sizeof(DirectoryItem_Impl));
osl_acquireDirectoryItem(static_cast<oslDirectoryItem>(pItemImpl));
CopyMemory( &pItemImpl->FindData, &aFindData, sizeof(WIN32_FIND_DATAW) );
rtl_uString_newFromString( &pItemImpl->m_pFullPath, strSysFilePath );
CopyMemory(&pItemImpl->FindData, &aFindData, sizeof(WIN32_FIND_DATAW));
rtl_uString_newFromString(&pItemImpl->m_pFullPath, strSysFilePath);
// MT: This costs 600ms startup time on fast v60x!
// GetCaseCorrectPathName( pItemImpl->szFullPath, pItemImpl->szFullPath, sizeof(pItemImpl->szFullPath) );
// MT: This costs 600ms startup time on fast v60x!
// GetCaseCorrectPathName( pItemImpl->szFullPath, pItemImpl->szFullPath, sizeof(pItemImpl->szFullPath) );
pItemImpl->uType = DIRECTORYITEM_FILE;
*pItem = pItemImpl;
pItemImpl->uType = DIRECTORYITEM_FILE;
*pItem = pItemImpl;
}
FindClose( hFind );
}
else
diff --git a/sal/osl/w32/file_url.cxx b/sal/osl/w32/file_url.cxx
index b096515..c8291c0 100644
--- a/sal/osl/w32/file_url.cxx
+++ b/sal/osl/w32/file_url.cxx
@@ -603,7 +603,7 @@
rtl_uString2String( &strUTF8, rtl_uString_getStr( strURL ), rtl_uString_getLength( strURL ), RTL_TEXTENCODING_UTF8, OUSTRING_TO_OSTRING_CVTFLAGS );
pszEncodedURL = static_cast<sal_Char*>(malloc( (rtl_string_getLength( strUTF8 ) * 3 + 1) * sizeof(sal_Char) ));
assert(pszEncodedURL); // Don't handle OOM conditions
pURLDest = pszEncodedURL;
pURLScan = rtl_string_getStr( strUTF8 );
nURLScanLen = rtl_string_getLength( strUTF8 );
diff --git a/sal/osl/w32/pipe.cxx b/sal/osl/w32/pipe.cxx
index b128143..f02a895 100644
--- a/sal/osl/w32/pipe.cxx
+++ b/sal/osl/w32/pipe.cxx
@@ -136,12 +136,14 @@
PSECURITY_DESCRIPTOR pSecDesc;
pSecDesc = static_cast< PSECURITY_DESCRIPTOR >(malloc(SECURITY_DESCRIPTOR_MIN_LENGTH));
assert(pSecDesc); // Don't handle OOM conditions
/* add a NULL disc. ACL to the security descriptor */
OSL_VERIFY(InitializeSecurityDescriptor(pSecDesc, SECURITY_DESCRIPTOR_REVISION));
OSL_VERIFY(SetSecurityDescriptorDacl(pSecDesc, TRUE, nullptr, FALSE));
pSecAttr = static_cast< PSECURITY_ATTRIBUTES >(malloc(sizeof(SECURITY_ATTRIBUTES)));
assert(pSecAttr); // Don't handle OOM conditions
pSecAttr->nLength = sizeof(SECURITY_ATTRIBUTES);
pSecAttr->lpSecurityDescriptor = pSecDesc;
pSecAttr->bInheritHandle = TRUE;
diff --git a/sal/osl/w32/security.cxx b/sal/osl/w32/security.cxx
index aeecf1b..f7e14e7 100644
--- a/sal/osl/w32/security.cxx
+++ b/sal/osl/w32/security.cxx
@@ -19,6 +19,7 @@
#include "system.h"
#include <cassert>
#include <osl/security.h>
#include <osl/diagnose.h>
#include <osl/thread.h>
@@ -782,6 +783,7 @@
WNetGetUserW(nullptr, nullptr, &needed);
pNameW = static_cast<sal_Unicode *>(malloc (needed*sizeof(sal_Unicode)));
assert(pNameW); // Don't handle OOM conditions
if (WNetGetUserW(nullptr, o3tl::toW(pNameW), &needed) == NO_ERROR)
{
diff --git a/setup_native/source/win32/customactions/regactivex/regactivex.cxx b/setup_native/source/win32/customactions/regactivex/regactivex.cxx
index 293a8c8..f7234a4 100644
--- a/setup_native/source/win32/customactions/regactivex/regactivex.cxx
+++ b/setup_native/source/win32/customactions/regactivex/regactivex.cxx
@@ -23,6 +23,7 @@
#include <windows.h>
#include <msiquery.h>
#include <cassert>
#include <string.h>
#include <malloc.h>
@@ -66,6 +67,7 @@
if ( nLen > nRemoveLen )
{
wchar_t* pProgramPath = static_cast<wchar_t*>( malloc( (nLen - nRemoveLen + 1) * sizeof(wchar_t) ) );
assert(pProgramPath); // Don't handle OOM conditions
wcsncpy( pProgramPath, pActiveXPath, nLen - nRemoveLen );
pProgramPath[ nLen - nRemoveLen ] = 0;
@@ -102,6 +104,7 @@
sz++;
DWORD nbytes = sz * sizeof( wchar_t );
wchar_t* buff = static_cast<wchar_t*>( malloc( nbytes ) );
assert(buff); // Don't handle OOM conditions
ZeroMemory( buff, nbytes );
MsiGetPropertyW( hMSI, pPropName, buff, &sz );
*ppValue = buff;
diff --git a/setup_native/source/win32/customactions/sellang/sellang.cxx b/setup_native/source/win32/customactions/sellang/sellang.cxx
index bde31d0..e82560f 100644
--- a/setup_native/source/win32/customactions/sellang/sellang.cxx
+++ b/setup_native/source/win32/customactions/sellang/sellang.cxx
@@ -27,6 +27,7 @@
#include <msiquery.h>
#include <malloc.h>
#include <cassert>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -44,6 +45,7 @@
sz++;
DWORD nbytes = sz * sizeof( char );
char* buff = static_cast<char*>( malloc( nbytes ) );
assert(buff); // Don't handle OOM conditions
ZeroMemory( buff, nbytes );
MsiGetPropertyA( hMSI, pPropName, buff, &sz );
*ppValue = buff;
diff --git a/setup_native/source/win32/customactions/tools/checkversion.cxx b/setup_native/source/win32/customactions/tools/checkversion.cxx
index ffb7a8a..daf2096 100644
--- a/setup_native/source/win32/customactions/tools/checkversion.cxx
+++ b/setup_native/source/win32/customactions/tools/checkversion.cxx
@@ -21,6 +21,7 @@
#include <windows.h>
#include <msiquery.h>
#include <cassert>
#include <string.h>
#include <malloc.h>
#include <stdio.h>
@@ -37,6 +38,7 @@
sz++;
DWORD nbytes = sz * sizeof( wchar_t );
wchar_t* buff = static_cast<wchar_t*>( malloc( nbytes ) );
assert(buff); // Don't handle OOM conditions
ZeroMemory( buff, nbytes );
MsiGetPropertyW( hMSI, pPropName, buff, &sz );
*ppValue = buff;
diff --git a/soltools/mkdepend/main.c b/soltools/mkdepend/main.c
index 844edb3..51b6c86 100644
--- a/soltools/mkdepend/main.c
+++ b/soltools/mkdepend/main.c
@@ -56,6 +56,7 @@
#endif
#include "def.h"
#include <assert.h>
#include <string.h>
#ifdef hpux
#define sigvec sigvector
@@ -522,7 +523,7 @@
char *copy(char const *str)
{
char *p = (char *)malloc(strlen(str) + 1);
assert(p); // Don't handle OOM conditions
strcpy(p, str);
return p;
}
@@ -718,6 +719,7 @@
new_string = path;
} else {
new_string = (char*)malloc(sizeof(char) * (strlen(path) + 2));
assert(new_string); // Don't handle OOM conditions
strcpy(new_string, path);
if (native_win_slashes)
strcat(new_string, "\\");
diff --git a/vcl/source/fontsubset/sft.cxx b/vcl/source/fontsubset/sft.cxx
index 972f5fb..7df64e4 100644
--- a/vcl/source/fontsubset/sft.cxx
+++ b/vcl/source/fontsubset/sft.cxx
@@ -635,14 +635,15 @@
return 0;
np = myPoints.size();
pa = static_cast<ControlPoint*>(calloc(np, sizeof(ControlPoint)));
assert(pa != nullptr);
if (np > 0)
memcpy( pa, &myPoints[0], np*sizeof(ControlPoint) );
{
pa = static_cast<ControlPoint*>(calloc(np, sizeof(ControlPoint)));
assert(pa != nullptr);
*pointArray = pa;
memcpy(pa, &myPoints[0], np * sizeof(ControlPoint));
*pointArray = pa;
}
return np;
}
@@ -2537,6 +2538,7 @@
}
NameRecord* rec = static_cast<NameRecord*>(calloc(n, sizeof(NameRecord)));
assert(rec);
for (i = 0; i < n; i++) {
int nLargestFixedOffsetPos = 6 + 10 + 12 * i;
diff --git a/vcl/win/gdi/salprn.cxx b/vcl/win/gdi/salprn.cxx
index d702be9..9f729a1 100644
--- a/vcl/win/gdi/salprn.cxx
+++ b/vcl/win/gdi/salprn.cxx
@@ -1324,6 +1324,7 @@
nCopies = 32765;
sal_uLong nDevSize = pDevMode->dmSize+pDevMode->dmDriverExtra;
LPDEVMODEW pNewDevMode = static_cast<LPDEVMODEW>(std::malloc( nDevSize ));
assert(pNewDevMode); // Don't handle OOM conditions
memcpy( pNewDevMode, pDevMode, nDevSize );
pNewDevMode->dmFields |= DM_COPIES;
pNewDevMode->dmCopies = static_cast<short>(static_cast<sal_uInt16>(nCopies));