[Analyzers][CPP]Changes to fix warning 26493 on PowerToys/tools (#23674)

This commit is contained in:
sosssego 2023-02-08 14:01:40 +00:00 committed by GitHub
parent c7f761a589
commit 10252c3c1e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 17 additions and 14 deletions

View File

@ -5,9 +5,10 @@
// disable warning 26471 - Don't use reinterpret_cast. A cast from void* can use static_cast // disable warning 26471 - Don't use reinterpret_cast. A cast from void* can use static_cast
// disable warning 26492 - Don't use const_cast to cast away const // disable warning 26492 - Don't use const_cast to cast away const
// disable warning 26493 - Don't use C-style casts
// Disable 26497 for winrt - This function function-name could be marked constexpr if compile-time evaluation is desired. // Disable 26497 for winrt - This function function-name could be marked constexpr if compile-time evaluation is desired.
#pragma warning(push) #pragma warning(push)
#pragma warning(disable : 26471 26492 26497) #pragma warning(disable : 26471 26492 26493 26497)
#include <wil/resource.h> #include <wil/resource.h>
#pragma warning(pop) #pragma warning(pop)

View File

@ -57,7 +57,7 @@ namespace
if (ERROR_INSUFFICIENT_BUFFER == (status = GetLastError())) if (ERROR_INSUFFICIENT_BUFFER == (status = GetLastError()))
{ {
dwBufferSize = dwBufferUsed; dwBufferSize = dwBufferUsed;
pRenderedContent = (LPWSTR)malloc(dwBufferSize); pRenderedContent = static_cast<LPWSTR>(malloc(dwBufferSize));
if (pRenderedContent) if (pRenderedContent)
{ {
EvtRender(NULL, hEvent, EvtRenderEventXml, dwBufferSize, pRenderedContent, &dwBufferUsed, &dwPropertyCount); EvtRender(NULL, hEvent, EvtRenderEventXml, dwBufferSize, pRenderedContent, &dwBufferUsed, &dwPropertyCount);

View File

@ -27,7 +27,7 @@ wstring GetVersion(path filePath)
{ {
if (size) if (size)
{ {
VS_FIXEDFILEINFO* verInfo = (VS_FIXEDFILEINFO*)lpBuffer; VS_FIXEDFILEINFO* verInfo = static_cast<VS_FIXEDFILEINFO*>(lpBuffer);
if (verInfo->dwSignature == 0xfeef04bd) if (verInfo->dwSignature == 0xfeef04bd)
{ {
version = version =

View File

@ -166,7 +166,7 @@ void ReportWindowsVersion(const filesystem::path& tmpDir)
{ {
NTSTATUS(WINAPI * RtlGetVersion) NTSTATUS(WINAPI * RtlGetVersion)
(LPOSVERSIONINFOEXW) = nullptr; (LPOSVERSIONINFOEXW) = nullptr;
*(FARPROC*)&RtlGetVersion = GetProcAddress(GetModuleHandleA("ntdll"), "RtlGetVersion"); *reinterpret_cast<FARPROC*>(& RtlGetVersion) = GetProcAddress(GetModuleHandleA("ntdll"), "RtlGetVersion");
if (RtlGetVersion) if (RtlGetVersion)
{ {
osInfo.dwOSVersionInfoSize = sizeof(osInfo); osInfo.dwOSVersionInfoSize = sizeof(osInfo);

View File

@ -126,7 +126,7 @@ namespace
stream << achValue; stream << achValue;
} }
stream << " > " << (LPCTSTR)value << "\n"; stream << " > " << reinterpret_cast<LPCTSTR>(value) << "\n";
} }
else else
{ {

View File

@ -15,7 +15,7 @@ namespace
}; };
auto callback = [](HMONITOR monitor, HDC, RECT*, LPARAM prm) -> BOOL { auto callback = [](HMONITOR monitor, HDC, RECT*, LPARAM prm) -> BOOL {
std::wostream& os = *((capture*)prm)->os; std::wostream& os = *(reinterpret_cast<capture*>(prm))->os;
MONITORINFOEX mi; MONITORINFOEX mi;
mi.cbSize = sizeof(mi); mi.cbSize = sizeof(mi);
@ -48,7 +48,7 @@ namespace
capture c; capture c;
c.os = &os; c.os = &os;
if (EnumDisplayMonitors(nullptr, nullptr, callback, (LPARAM)&c)) if (EnumDisplayMonitors(nullptr, nullptr, callback, reinterpret_cast<LPARAM>(& c)))
{ {
os << "EnumDisplayMonitors OK\n"; os << "EnumDisplayMonitors OK\n";
} }

View File

@ -221,7 +221,7 @@ void LogWMI()
// on a particular host computer. // on a particular host computer.
IWbemLocator* pLocator = 0; IWbemLocator* pLocator = 0;
hres = CoCreateInstance(CLSID_WbemLocator, 0, CLSCTX_INPROC_SERVER, IID_IWbemLocator, (LPVOID*)&pLocator); hres = CoCreateInstance(CLSID_WbemLocator, 0, CLSCTX_INPROC_SERVER, IID_IWbemLocator, reinterpret_cast<LPVOID*>(&pLocator));
if (FAILED(hres)) if (FAILED(hres))
{ {
Logger::log(L"Failed to create IWbemLocator object. Error code = ", hres); Logger::log(L"Failed to create IWbemLocator object. Error code = ", hres);
@ -346,7 +346,7 @@ void LogWMICIMV2()
// on a particular host computer. // on a particular host computer.
IWbemLocator* pLocator = 0; IWbemLocator* pLocator = 0;
hres = CoCreateInstance(CLSID_WbemLocator, 0, CLSCTX_INPROC_SERVER, IID_IWbemLocator, (LPVOID*)&pLocator); hres = CoCreateInstance(CLSID_WbemLocator, 0, CLSCTX_INPROC_SERVER, IID_IWbemLocator, reinterpret_cast<LPVOID*>(&pLocator));
if (FAILED(hres)) if (FAILED(hres))
{ {
Logger::log(L"Failed to create IWbemLocator object. Error code = ", hres); Logger::log(L"Failed to create IWbemLocator object. Error code = ", hres);

View File

@ -7,11 +7,12 @@
// disable warning 26471 - Don't use reinterpret_cast. A cast from void* can use static_cast // disable warning 26471 - Don't use reinterpret_cast. A cast from void* can use static_cast
// disable warning 26492 - Don't use const_cast to cast away const on winrt // disable warning 26492 - Don't use const_cast to cast away const on winrt
// disable warning 26493 - Don't use C-style casts
// Disable 26497 for winrt - This function function-name could be marked constexpr if compile-time evaluation is desired. // Disable 26497 for winrt - This function function-name could be marked constexpr if compile-time evaluation is desired.
#pragma warning(push) #pragma warning(push)
#pragma warning(disable : 26471 26492 26497) #pragma warning(disable : 26471 26492 26493 26497)
#include <wil/com.h> #include <wil/com.h>
#pragma warning(push) #pragma warning(pop)
#include <winrt/Windows.Foundation.h> #include <winrt/Windows.Foundation.h>

View File

@ -7,11 +7,12 @@
// disable warning 26471 - Don't use reinterpret_cast. A cast from void* can use static_cast // disable warning 26471 - Don't use reinterpret_cast. A cast from void* can use static_cast
// disable warning 26492 - Don't use const_cast to cast away const // disable warning 26492 - Don't use const_cast to cast away const
// disable warning 26493 - Don't use C-style casts
// Disable 26497 for winrt - This function function-name could be marked constexpr if compile-time evaluation is desired. // Disable 26497 for winrt - This function function-name could be marked constexpr if compile-time evaluation is desired.
#pragma warning(push) #pragma warning(push)
#pragma warning(disable : 26471 26492 26497) #pragma warning(disable : 26471 26492 26493 26497)
#include <wil/com.h> #include <wil/com.h>
#pragma warning(push) #pragma warning(pop)
#include <wil/resource.h> #include <wil/resource.h>
@ -178,7 +179,7 @@ void ReportAllWebcams()
std::string friendlyName; std::string friendlyName;
for (wchar_t c : wideFriendlyName) for (wchar_t c : wideFriendlyName)
{ {
friendlyName += (char)c; friendlyName += static_cast<char>(c);
} }
log() << "Webcam " << friendlyName << '\n'; log() << "Webcam " << friendlyName << '\n';