From 3b25ea6d83041c03d06a47fb5e278372181b8a6d Mon Sep 17 00:00:00 2001 From: Mike Kaganski Date: Sun, 31 Mar 2019 16:45:29 +0300 Subject: 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 --- sal/osl/w32/file_dirvol.cxx | 28 +++++++++++++++++++--------- sal/osl/w32/file_url.cxx | 2 +- sal/osl/w32/pipe.cxx | 2 ++ sal/osl/w32/security.cxx | 2 ++ 4 files changed, 24 insertions(+), 10 deletions(-) (limited to 'sal') diff --git a/sal/osl/w32/file_dirvol.cxx b/sal/osl/w32/file_dirvol.cxx index cfdf957ef0de..36a4b5d4013d 100644 --- a/sal/osl/w32/file_dirvol.cxx +++ b/sal/osl/w32/file_dirvol.cxx @@ -345,11 +345,12 @@ static HANDLE WINAPI OpenDirectory( rtl_uString* pPath) } 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(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 @@ static oslFileError osl_openLocalRoot( Directory_Impl *pDirImpl; pDirImpl = static_cast(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 @@ static oslFileError osl_openFileDirectory( *pDirectory = nullptr; Directory_Impl *pDirImpl = static_cast(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 @@ static oslFileError osl_openNetworkServer( Directory_Impl *pDirImpl; pDirImpl = static_cast(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 @@ oslFileError SAL_CALL osl_getDirectoryItem(rtl_uString *strFilePath, oslDirector { DirectoryItem_Impl *pItemImpl = static_cast(malloc(sizeof(DirectoryItem_Impl))); + if (!pItemImpl) + error = osl_File_E_NOMEM; - ZeroMemory( pItemImpl, sizeof(DirectoryItem_Impl) ); - osl_acquireDirectoryItem( static_cast(pItemImpl) ); + if (osl_File_E_None == error) + { + ZeroMemory(pItemImpl, sizeof(DirectoryItem_Impl)); + osl_acquireDirectoryItem(static_cast(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 b096515902ba..c8291c056674 100644 --- a/sal/osl/w32/file_url.cxx +++ b/sal/osl/w32/file_url.cxx @@ -603,7 +603,7 @@ static void osl_encodeURL_( rtl_uString *strURL, rtl_String **pstrEncodedURL ) rtl_uString2String( &strUTF8, rtl_uString_getStr( strURL ), rtl_uString_getLength( strURL ), RTL_TEXTENCODING_UTF8, OUSTRING_TO_OSTRING_CVTFLAGS ); pszEncodedURL = static_cast(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 b128143702a1..f02a8951f3cb 100644 --- a/sal/osl/w32/pipe.cxx +++ b/sal/osl/w32/pipe.cxx @@ -136,12 +136,14 @@ oslPipe SAL_CALL osl_createPipe(rtl_uString *strPipeName, oslPipeOptions Options 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 aeecf1b8ca63..f7e14e7e32ae 100644 --- a/sal/osl/w32/security.cxx +++ b/sal/osl/w32/security.cxx @@ -19,6 +19,7 @@ #include "system.h" +#include #include #include #include @@ -782,6 +783,7 @@ static bool getUserNameImpl(oslSecurity Security, rtl_uString **strName, bool b WNetGetUserW(nullptr, nullptr, &needed); pNameW = static_cast(malloc (needed*sizeof(sal_Unicode))); + assert(pNameW); // Don't handle OOM conditions if (WNetGetUserW(nullptr, o3tl::toW(pNameW), &needed) == NO_ERROR) { -- cgit