Address code analysis warnings

Signed-off-by: Simon Rozman <simon@rozman.si>
This commit is contained in:
2020-02-12 19:27:07 +01:00
parent 7d2062d3bf
commit 73619821ee
24 changed files with 473 additions and 454 deletions

View File

@@ -32,13 +32,13 @@ winstd::bstr::~bstr()
}
void winstd::bstr::free_internal()
void winstd::bstr::free_internal() noexcept
{
SysFreeString(m_h);
}
winstd::bstr::handle_type winstd::bstr::duplicate_internal(_In_ handle_type h) const
winstd::bstr::handle_type winstd::bstr::duplicate_internal(_In_ handle_type h) const noexcept
{
return SysAllocStringLen(h, SysStringLen(h));
}
@@ -48,6 +48,7 @@ winstd::bstr::handle_type winstd::bstr::duplicate_internal(_In_ handle_type h) c
// winstd::variant
//////////////////////////////////////////////////////////////////////
#pragma warning(suppress: 26432) // Copy constructor and assignment operator are also present, but not detected by code analysis as they are using base type source object reference.
winstd::variant::~variant()
{
VariantClear(this);

View File

@@ -34,13 +34,13 @@ winstd::cert_context::~cert_context()
}
void winstd::cert_context::free_internal()
void winstd::cert_context::free_internal() noexcept
{
CertFreeCertificateContext(m_h);
}
winstd::cert_context::handle_type winstd::cert_context::duplicate_internal(_In_ handle_type h) const
winstd::cert_context::handle_type winstd::cert_context::duplicate_internal(_In_ handle_type h) const noexcept
{
return CertDuplicateCertificateContext(h);
}
@@ -57,13 +57,13 @@ winstd::cert_chain_context::~cert_chain_context()
}
void winstd::cert_chain_context::free_internal()
void winstd::cert_chain_context::free_internal() noexcept
{
CertFreeCertificateChain(m_h);
}
winstd::cert_chain_context::handle_type winstd::cert_chain_context::duplicate_internal(_In_ handle_type h) const
winstd::cert_chain_context::handle_type winstd::cert_chain_context::duplicate_internal(_In_ handle_type h) const noexcept
{
return CertDuplicateCertificateChain(h);
}
@@ -80,7 +80,7 @@ winstd::cert_store::~cert_store()
}
void winstd::cert_store::free_internal()
void winstd::cert_store::free_internal() noexcept
{
CertCloseStore(m_h, 0);
}
@@ -97,7 +97,7 @@ winstd::crypt_prov::~crypt_prov()
}
void winstd::crypt_prov::free_internal()
void winstd::crypt_prov::free_internal() noexcept
{
CryptReleaseContext(m_h, 0);
}
@@ -114,13 +114,13 @@ winstd::crypt_hash::~crypt_hash()
}
void winstd::crypt_hash::free_internal()
void winstd::crypt_hash::free_internal() noexcept
{
CryptDestroyHash(m_h);
}
winstd::crypt_hash::handle_type winstd::crypt_hash::duplicate_internal(_In_ handle_type h) const
winstd::crypt_hash::handle_type winstd::crypt_hash::duplicate_internal(_In_ handle_type h) const noexcept
{
handle_type hNew = invalid;
return CryptDuplicateHash(h, NULL, 0, &hNew) ? hNew : invalid;
@@ -155,7 +155,7 @@ bool winstd::crypt_key::create_exp1(_In_ HCRYPTPROV hProv, _In_ DWORD dwKeySpec)
// Get the byte length of the key.
size_t
size_key = *(DWORD*)&key_blob[12]/8,
size_key = *reinterpret_cast<DWORD*>(&key_blob[12])/8,
size_prime = size_key/2;
// Modify the Exponent in Key BLOB format
@@ -163,7 +163,7 @@ bool winstd::crypt_key::create_exp1(_In_ HCRYPTPROV hProv, _In_ DWORD dwKeySpec)
// Convert pubexp in rsapubkey to 1
LPBYTE ptr = &key_blob[16];
*(DWORD*)ptr = 1;
*reinterpret_cast<DWORD*>(ptr) = 1;
ptr += sizeof(DWORD);
// Skip modulus, prime1, prime2
@@ -189,7 +189,7 @@ bool winstd::crypt_key::create_exp1(_In_ HCRYPTPROV hProv, _In_ DWORD dwKeySpec)
memset(ptr + 1, 0, size_key - 1);
// Import the exponent-of-one private key.
if (CryptImportKey(hProv, key_blob.data(), (DWORD)key_blob.size(), 0, 0, &h)) {
if (CryptImportKey(hProv, key_blob.data(), static_cast<DWORD>(key_blob.size()), 0, 0, &h)) {
attach(h);
return true;
}
@@ -201,13 +201,13 @@ bool winstd::crypt_key::create_exp1(_In_ HCRYPTPROV hProv, _In_ DWORD dwKeySpec)
}
void winstd::crypt_key::free_internal()
void winstd::crypt_key::free_internal() noexcept
{
CryptDestroyKey(m_h);
}
winstd::crypt_key::handle_type winstd::crypt_key::duplicate_internal(_In_ handle_type h) const
winstd::crypt_key::handle_type winstd::crypt_key::duplicate_internal(_In_ handle_type h) const noexcept
{
handle_type hNew = invalid;
return CryptDuplicateKey(h, NULL, 0, &hNew) ? hNew : invalid;
@@ -218,6 +218,7 @@ winstd::crypt_key::handle_type winstd::crypt_key::duplicate_internal(_In_ handle
// winstd::data_blob
//////////////////////////////////////////////////////////////////////
#pragma warning(suppress: 26432) // Copy constructor and assignment operator are also present, but not detected by code analysis as they are using base type source object reference.
winstd::data_blob::~data_blob()
{
if (pbData != NULL)

View File

@@ -27,17 +27,18 @@
// winstd::eap_attr
//////////////////////////////////////////////////////////////////////
#pragma warning(suppress: 26432) // Copy constructor and assignment operator are also present, but not detected by code analysis as they are using base type source object reference.
winstd::eap_attr::~eap_attr()
{
if (pValue)
delete []pValue;
delete [] pValue;
}
void winstd::eap_attr::create_ms_mppe_key(_In_ BYTE bVendorType, _In_count_(nKeySize) LPCBYTE pbKey, _In_ BYTE nKeySize)
{
BYTE nPaddingLength = (BYTE)((16 - (1 + (DWORD)nKeySize)) % 16);
DWORD dwLengthNew =
const BYTE nPaddingLength = static_cast<BYTE>((16 - (1 + static_cast<DWORD>(nKeySize))) % 16);
const DWORD dwLengthNew =
4 + // Vendor-Id
1 + // Vendor type
1 + // Vendor length
@@ -54,7 +55,7 @@ void winstd::eap_attr::create_ms_mppe_key(_In_ BYTE bVendorType, _In_count_(nKey
p[2] = 0x01; // --|
p[3] = 0x37; // --^
p[4] = bVendorType; // Vendor type
p[5] = (BYTE)(dwLengthNew - 4); // Vendor length
p[5] = static_cast<BYTE>(dwLengthNew - 4); // Vendor length
p[6] = 0x00; // Salt
p[7] = 0x00; // --^
p[8] = nKeySize; // Key-Length
@@ -65,6 +66,7 @@ void winstd::eap_attr::create_ms_mppe_key(_In_ BYTE bVendorType, _In_count_(nKey
if (pValue)
delete [] pValue;
#pragma warning(suppress: 26812) // EAP_ATTRIBUTE_TYPE is unscoped.
eaType = eatVendorSpecific;
dwLength = dwLengthNew;
pValue = p;
@@ -85,16 +87,16 @@ winstd::eap_packet::~eap_packet()
}
void winstd::eap_packet::free_internal()
void winstd::eap_packet::free_internal() noexcept
{
HeapFree(GetProcessHeap(), 0, m_h);
}
winstd::eap_packet::handle_type winstd::eap_packet::duplicate_internal(_In_ handle_type h) const
winstd::eap_packet::handle_type winstd::eap_packet::duplicate_internal(_In_ handle_type h) const noexcept
{
WORD n = ntohs(*(WORD*)h->Length);
handle_type h2 = (handle_type)HeapAlloc(GetProcessHeap(), 0, n);
const WORD n = ntohs(*reinterpret_cast<WORD*>(h->Length));
handle_type h2 = static_cast<handle_type>(HeapAlloc(GetProcessHeap(), 0, n));
if (h2 == invalid) {
SetLastError(ERROR_OUTOFMEMORY);
return invalid;
@@ -119,22 +121,22 @@ winstd::eap_method_info_array::~eap_method_info_array()
/// \cond internal
void winstd::eap_method_info_array::free_internal()
void winstd::eap_method_info_array::free_internal() noexcept
{
for (DWORD i = 0; i < dwNumberOfMethods; i++)
free_internal(pEapMethods + i);
EapHostPeerFreeMemory((BYTE*)pEapMethods);
EapHostPeerFreeMemory(reinterpret_cast<BYTE*>(pEapMethods));
}
void winstd::eap_method_info_array::free_internal(_In_ EAP_METHOD_INFO *pMethodInfo)
void winstd::eap_method_info_array::free_internal(_In_ EAP_METHOD_INFO *pMethodInfo) noexcept
{
if (pMethodInfo->pInnerMethodInfo)
free_internal(pMethodInfo->pInnerMethodInfo);
EapHostPeerFreeMemory((BYTE*)pMethodInfo->pwszAuthorName);
EapHostPeerFreeMemory((BYTE*)pMethodInfo->pwszFriendlyName);
EapHostPeerFreeMemory(reinterpret_cast<BYTE*>(pMethodInfo->pwszAuthorName));
EapHostPeerFreeMemory(reinterpret_cast<BYTE*>(pMethodInfo->pwszFriendlyName));
}
/// \endcond

View File

@@ -123,7 +123,7 @@ winstd::event_provider::~event_provider()
}
void winstd::event_provider::free_internal()
void winstd::event_provider::free_internal() noexcept
{
EventUnregister(m_h);
}
@@ -160,7 +160,7 @@ winstd::event_session::~event_session()
}
void winstd::event_session::free_internal()
void winstd::event_session::free_internal() noexcept
{
ControlTrace(m_h, name(), m_prop.get(), EVENT_TRACE_CONTROL_STOP);
}
@@ -197,7 +197,7 @@ winstd::event_trace::~event_trace()
}
void winstd::event_trace::free_internal()
void winstd::event_trace::free_internal() noexcept
{
CloseTrace(m_h);
}

View File

@@ -36,7 +36,7 @@ winstd::sec_credentials::~sec_credentials()
}
void winstd::sec_credentials::free_internal()
void winstd::sec_credentials::free_internal() noexcept
{
FreeCredentialsHandle(m_h);
delete m_h;
@@ -56,7 +56,7 @@ winstd::sec_context::~sec_context()
}
void winstd::sec_context::free_internal()
void winstd::sec_context::free_internal() noexcept
{
DeleteSecurityContext(m_h);
delete m_h;

View File

@@ -34,7 +34,7 @@ winstd::setup_device_info_list::~setup_device_info_list()
}
void winstd::setup_device_info_list::free_internal()
void winstd::setup_device_info_list::free_internal() noexcept
{
SetupDiDestroyDeviceInfoList(m_h);
}

View File

@@ -32,7 +32,7 @@ winstd::wlan_handle::~wlan_handle()
}
void winstd::wlan_handle::free_internal()
void winstd::wlan_handle::free_internal() noexcept
{
WlanCloseHandle(m_h, NULL);
}

View File

@@ -25,7 +25,7 @@
// StringToGuidA
//////////////////////////////////////////////////////////////////////
_Success_(return) BOOL WINSTD_API StringToGuidA(_In_z_ LPCSTR lpszGuid, _Out_ LPGUID lpGuid, _Out_opt_ LPCSTR *lpszGuidEnd)
_Success_(return) BOOL WINSTD_API StringToGuidA(_In_z_ LPCSTR lpszGuid, _Out_ LPGUID lpGuid, _Out_opt_ LPCSTR *lpszGuidEnd) noexcept
{
GUID g;
LPSTR lpszEnd;
@@ -44,7 +44,7 @@ _Success_(return) BOOL WINSTD_API StringToGuidA(_In_z_ LPCSTR lpszGuid, _Out_ LP
ulTmp = strtoul(lpszGuid, &lpszEnd, 16);
if (errno == ERANGE || ulTmp > 0xFFFF) return FALSE;
g.Data2 = (unsigned short)ulTmp;
g.Data2 = static_cast<unsigned short>(ulTmp);
lpszGuid = lpszEnd;
if (*lpszGuid != '-') return FALSE;
@@ -52,7 +52,7 @@ _Success_(return) BOOL WINSTD_API StringToGuidA(_In_z_ LPCSTR lpszGuid, _Out_ LP
ulTmp = strtoul(lpszGuid, &lpszEnd, 16);
if (errno == ERANGE || ulTmp > 0xFFFF) return FALSE;
g.Data3 = (unsigned short)ulTmp;
g.Data3 = static_cast<unsigned short>(ulTmp);
lpszGuid = lpszEnd;
if (*lpszGuid != '-') return FALSE;
@@ -60,8 +60,8 @@ _Success_(return) BOOL WINSTD_API StringToGuidA(_In_z_ LPCSTR lpszGuid, _Out_ LP
ulTmp = strtoul(lpszGuid, &lpszEnd, 16);
if (errno == ERANGE || ulTmp > 0xFFFF) return FALSE;
g.Data4[0] = (unsigned char)((ulTmp >> 8) & 0xff);
g.Data4[1] = (unsigned char)( ulTmp & 0xff);
g.Data4[0] = static_cast<unsigned char>((ulTmp >> 8) & 0xff);
g.Data4[1] = static_cast<unsigned char>( ulTmp & 0xff);
lpszGuid = lpszEnd;
if (*lpszGuid != '-') return FALSE;
@@ -69,12 +69,12 @@ _Success_(return) BOOL WINSTD_API StringToGuidA(_In_z_ LPCSTR lpszGuid, _Out_ LP
ullTmp = _strtoui64(lpszGuid, &lpszEnd, 16);
if (errno == ERANGE || ullTmp > 0xFFFFFFFFFFFF) return FALSE;
g.Data4[2] = (unsigned char)((ullTmp >> 40) & 0xff);
g.Data4[3] = (unsigned char)((ullTmp >> 32) & 0xff);
g.Data4[4] = (unsigned char)((ullTmp >> 24) & 0xff);
g.Data4[5] = (unsigned char)((ullTmp >> 16) & 0xff);
g.Data4[6] = (unsigned char)((ullTmp >> 8) & 0xff);
g.Data4[7] = (unsigned char)( ullTmp & 0xff);
g.Data4[2] = static_cast<unsigned char>((ullTmp >> 40) & 0xff);
g.Data4[3] = static_cast<unsigned char>((ullTmp >> 32) & 0xff);
g.Data4[4] = static_cast<unsigned char>((ullTmp >> 24) & 0xff);
g.Data4[5] = static_cast<unsigned char>((ullTmp >> 16) & 0xff);
g.Data4[6] = static_cast<unsigned char>((ullTmp >> 8) & 0xff);
g.Data4[7] = static_cast<unsigned char>( ullTmp & 0xff);
lpszGuid = lpszEnd;
if (*lpszGuid != '}') return FALSE;
@@ -88,7 +88,7 @@ _Success_(return) BOOL WINSTD_API StringToGuidA(_In_z_ LPCSTR lpszGuid, _Out_ LP
}
_Success_(return) BOOL WINSTD_API StringToGuidW(_In_z_ LPCWSTR lpszGuid, _Out_ LPGUID lpGuid, _Out_opt_ LPCWSTR *lpszGuidEnd)
_Success_(return) BOOL WINSTD_API StringToGuidW(_In_z_ LPCWSTR lpszGuid, _Out_ LPGUID lpGuid, _Out_opt_ LPCWSTR *lpszGuidEnd) noexcept
{
GUID g;
LPWSTR lpszEnd;
@@ -107,7 +107,7 @@ _Success_(return) BOOL WINSTD_API StringToGuidW(_In_z_ LPCWSTR lpszGuid, _Out_ L
ulTmp = wcstoul(lpszGuid, &lpszEnd, 16);
if (errno == ERANGE || ulTmp > 0xFFFF) return FALSE;
g.Data2 = (unsigned short)ulTmp;
g.Data2 = static_cast<unsigned short>(ulTmp);
lpszGuid = lpszEnd;
if (*lpszGuid != '-') return FALSE;
@@ -115,7 +115,7 @@ _Success_(return) BOOL WINSTD_API StringToGuidW(_In_z_ LPCWSTR lpszGuid, _Out_ L
ulTmp = wcstoul(lpszGuid, &lpszEnd, 16);
if (errno == ERANGE || ulTmp > 0xFFFF) return FALSE;
g.Data3 = (unsigned short)ulTmp;
g.Data3 = static_cast<unsigned short>(ulTmp);
lpszGuid = lpszEnd;
if (*lpszGuid != '-') return FALSE;
@@ -123,8 +123,8 @@ _Success_(return) BOOL WINSTD_API StringToGuidW(_In_z_ LPCWSTR lpszGuid, _Out_ L
ulTmp = wcstoul(lpszGuid, &lpszEnd, 16);
if (errno == ERANGE || ulTmp > 0xFFFF) return FALSE;
g.Data4[0] = (unsigned char)((ulTmp >> 8) & 0xff);
g.Data4[1] = (unsigned char)( ulTmp & 0xff);
g.Data4[0] = static_cast<unsigned char>((ulTmp >> 8) & 0xff);
g.Data4[1] = static_cast<unsigned char>( ulTmp & 0xff);
lpszGuid = lpszEnd;
if (*lpszGuid != '-') return FALSE;
@@ -132,12 +132,12 @@ _Success_(return) BOOL WINSTD_API StringToGuidW(_In_z_ LPCWSTR lpszGuid, _Out_ L
ullTmp = _wcstoui64(lpszGuid, &lpszEnd, 16);
if (errno == ERANGE || ullTmp > 0xFFFFFFFFFFFF) return FALSE;
g.Data4[2] = (unsigned char)((ullTmp >> 40) & 0xff);
g.Data4[3] = (unsigned char)((ullTmp >> 32) & 0xff);
g.Data4[4] = (unsigned char)((ullTmp >> 24) & 0xff);
g.Data4[5] = (unsigned char)((ullTmp >> 16) & 0xff);
g.Data4[6] = (unsigned char)((ullTmp >> 8) & 0xff);
g.Data4[7] = (unsigned char)( ullTmp & 0xff);
g.Data4[2] = static_cast<unsigned char>((ullTmp >> 40) & 0xff);
g.Data4[3] = static_cast<unsigned char>((ullTmp >> 32) & 0xff);
g.Data4[4] = static_cast<unsigned char>((ullTmp >> 24) & 0xff);
g.Data4[5] = static_cast<unsigned char>((ullTmp >> 16) & 0xff);
g.Data4[6] = static_cast<unsigned char>((ullTmp >> 8) & 0xff);
g.Data4[7] = static_cast<unsigned char>( ullTmp & 0xff);
lpszGuid = lpszEnd;
if (*lpszGuid != '}') return FALSE;
@@ -162,7 +162,7 @@ winstd::library::~library()
}
void winstd::library::free_internal()
void winstd::library::free_internal() noexcept
{
FreeLibrary(m_h);
}
@@ -174,7 +174,11 @@ void winstd::library::free_internal()
winstd::critical_section::critical_section()
{
InitializeCriticalSection(&m_data);
__try {
InitializeCriticalSection(&m_data);
} __except(EXCEPTION_EXECUTE_HANDLER) {
throw std::runtime_error("InitializeCriticalSection failed");
}
}
@@ -196,7 +200,7 @@ winstd::find_file::~find_file()
}
void winstd::find_file::free_internal()
void winstd::find_file::free_internal() noexcept
{
FindClose(m_h);
}
@@ -215,7 +219,7 @@ winstd::heap::~heap()
}
bool winstd::heap::enumerate()
bool winstd::heap::enumerate() noexcept
{
assert(m_h != invalid);
@@ -243,7 +247,7 @@ bool winstd::heap::enumerate()
}
}
DWORD dwResult = GetLastError();
const DWORD dwResult = GetLastError();
if (dwResult != ERROR_NO_MORE_ITEMS)
OutputDebugStr(_T("HeapWalk failed (error %u).\n"), dwResult);
@@ -254,7 +258,7 @@ bool winstd::heap::enumerate()
}
void winstd::heap::free_internal()
void winstd::heap::free_internal() noexcept
{
enumerate();
HeapDestroy(m_h);
@@ -265,7 +269,7 @@ void winstd::heap::free_internal()
// winstd::actctx_activator
//////////////////////////////////////////////////////////////////////
winstd::actctx_activator::actctx_activator(_In_ HANDLE hActCtx)
winstd::actctx_activator::actctx_activator(_In_ HANDLE hActCtx) noexcept
{
if (!ActivateActCtx(hActCtx, &m_cookie))
m_cookie = 0;
@@ -283,7 +287,7 @@ winstd::actctx_activator::~actctx_activator()
// winstd::user_impersonator
//////////////////////////////////////////////////////////////////////
winstd::user_impersonator::user_impersonator(_In_opt_ HANDLE hToken)
winstd::user_impersonator::user_impersonator(_In_opt_ HANDLE hToken) noexcept
{
m_cookie = hToken && ImpersonateLoggedOnUser(hToken);
}
@@ -300,7 +304,7 @@ winstd::user_impersonator::~user_impersonator()
// winstd::console_ctrl_handler
//////////////////////////////////////////////////////////////////////
winstd::console_ctrl_handler::console_ctrl_handler(_In_opt_ PHANDLER_ROUTINE HandlerRoutine) :
winstd::console_ctrl_handler::console_ctrl_handler(_In_opt_ PHANDLER_ROUTINE HandlerRoutine) noexcept :
m_handler(HandlerRoutine)
{
m_cookie = SetConsoleCtrlHandler(m_handler, TRUE);
@@ -325,7 +329,7 @@ winstd::vmemory::~vmemory()
}
void winstd::vmemory::free_internal()
void winstd::vmemory::free_internal() noexcept
{
VirtualFreeEx(m_proc, m_h, 0, MEM_RELEASE);
}
@@ -342,7 +346,7 @@ winstd::reg_key::~reg_key()
}
void winstd::reg_key::free_internal()
void winstd::reg_key::free_internal() noexcept
{
RegCloseKey(m_h);
}
@@ -359,7 +363,7 @@ winstd::security_id::~security_id()
}
void winstd::security_id::free_internal()
void winstd::security_id::free_internal() noexcept
{
FreeSid(m_h);
}

View File

@@ -34,7 +34,7 @@ winstd::addrinfo::~addrinfo()
}
void winstd::addrinfo::free_internal()
void winstd::addrinfo::free_internal() noexcept
{
FreeAddrInfo(m_h);
}

View File

@@ -30,5 +30,5 @@
winstd::wintrust::~wintrust()
{
m_wtd.dwStateAction = WTD_STATEACTION_CLOSE;
WinVerifyTrust(m_hwnd, (GUID*)&m_action, &m_wtd);
WinVerifyTrust(m_hwnd, &m_action, &m_wtd);
}