Skip to content

Commit

Permalink
[Analyzers][CPP]Turn on warning 26471 (microsoft#23103)
Browse files Browse the repository at this point in the history
Don't use reinterpret_cast. A cast from void* can use static_cast
  • Loading branch information
sosssego authored Jan 16, 2023
1 parent 1a1f435 commit d84a13b
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 9 deletions.
2 changes: 1 addition & 1 deletion CppRuleSet.ruleset
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
<Rule Id="C26464" Action="Error" />
<Rule Id="C26465" Action="Hidden" />
<Rule Id="C26466" Action="Error" />
<Rule Id="C26471" Action="Hidden" />
<Rule Id="C26471" Action="Error" />
<Rule Id="C26472" Action="Hidden" />
<Rule Id="C26473" Action="Hidden" />
<Rule Id="C26474" Action="Hidden" />
Expand Down
2 changes: 1 addition & 1 deletion src/ActionRunner/actionRunner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
hMapFile = OpenFileMappingW(FILE_MAP_WRITE, FALSE, pidFile.data());
if (hMapFile)
{
pidBuffer = reinterpret_cast<PDWORD>(MapViewOfFile(hMapFile, FILE_MAP_ALL_ACCESS, 0, 0, sizeof(DWORD)));
pidBuffer = static_cast<PDWORD>(MapViewOfFile(hMapFile, FILE_MAP_ALL_ACCESS, 0, 0, sizeof(DWORD)));
if (pidBuffer)
{
*pidBuffer = 0;
Expand Down
5 changes: 5 additions & 0 deletions src/common/utils/exec.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@

#define WIN32_LEAN_AND_MEAN
#include <Windows.h>

// disable warning 26471 - Don't use reinterpret_cast. A cast from void* can use static_cast
#pragma warning(push)
#pragma warning(disable: 26471)
#include <wil/resource.h>
#pragma warning(pop)

#include <optional>
#include <string>
Expand Down
2 changes: 1 addition & 1 deletion src/modules/alwaysontop/AlwaysOnTop/AlwaysOnTop.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class AlwaysOnTop : public SettingsObserver
if (!thisRef && (message == WM_CREATE))
{
const auto createStruct = reinterpret_cast<LPCREATESTRUCT>(lparam);
thisRef = reinterpret_cast<AlwaysOnTop*>(createStruct->lpCreateParams);
thisRef = static_cast<AlwaysOnTop*>(createStruct->lpCreateParams);
SetWindowLongPtr(window, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(thisRef));
}

Expand Down
2 changes: 1 addition & 1 deletion src/modules/alwaysontop/AlwaysOnTop/WindowBorder.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class WindowBorder : public SettingsObserver
if ((thisRef == nullptr) && (message == WM_CREATE))
{
auto createStruct = reinterpret_cast<LPCREATESTRUCT>(lparam);
thisRef = reinterpret_cast<WindowBorder*>(createStruct->lpCreateParams);
thisRef = static_cast<WindowBorder*>(createStruct->lpCreateParams);
SetWindowLongPtr(window, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(thisRef));
}

Expand Down
2 changes: 1 addition & 1 deletion src/modules/fancyzones/FancyZonesLib/FancyZones.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,7 @@ LRESULT CALLBACK FancyZones::s_WndProc(HWND window, UINT message, WPARAM wparam,
if (!thisRef && (message == WM_CREATE))
{
const auto createStruct = reinterpret_cast<LPCREATESTRUCT>(lparam);
thisRef = reinterpret_cast<FancyZones*>(createStruct->lpCreateParams);
thisRef = static_cast<FancyZones*>(createStruct->lpCreateParams);
SetWindowLongPtr(window, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(thisRef));
}

Expand Down
2 changes: 1 addition & 1 deletion src/modules/fancyzones/FancyZonesLib/WorkArea.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,7 @@ LRESULT CALLBACK WorkArea::s_WndProc(HWND window, UINT message, WPARAM wparam, L
if ((thisRef == nullptr) && (message == WM_CREATE))
{
auto createStruct = reinterpret_cast<LPCREATESTRUCT>(lparam);
thisRef = reinterpret_cast<WorkArea*>(createStruct->lpCreateParams);
thisRef = static_cast<WorkArea*>(createStruct->lpCreateParams);
SetWindowLongPtr(window, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(thisRef));
}

Expand Down
2 changes: 1 addition & 1 deletion src/modules/fancyzones/FancyZonesTests/UnitTests/Util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ BOOL RegisterDLLWindowClass(LPCWSTR szClassName, Mocks::HwndCreator* creator)
DWORD WINAPI ThreadProc(LPVOID lpParam)
{
MSG messages;
Mocks::HwndCreator* creator = reinterpret_cast<Mocks::HwndCreator*>(lpParam);
Mocks::HwndCreator* creator = static_cast<Mocks::HwndCreator*>(lpParam);
if (!creator)
return static_cast<DWORD>(-1);

Expand Down
4 changes: 2 additions & 2 deletions src/modules/powerrename/lib/PowerRenameManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,7 @@ DWORD WINAPI CPowerRenameManager::s_fileOpWorkerThread(_In_ void* pv)
{
if (SUCCEEDED(CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE)))
{
WorkerThreadData* pwtd = reinterpret_cast<WorkerThreadData*>(pv);
WorkerThreadData* pwtd = static_cast<WorkerThreadData*>(pv);
if (pwtd)
{
bool closeUIWindowAfterRenaming = true;
Expand Down Expand Up @@ -914,7 +914,7 @@ DWORD WINAPI CPowerRenameManager::s_regexWorkerThread(_In_ void* pv)
try
{
winrt::check_hresult(CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE));
WorkerThreadData* pwtd = reinterpret_cast<WorkerThreadData*>(pv);
WorkerThreadData* pwtd = static_cast<WorkerThreadData*>(pv);
if (pwtd)
{
PostMessage(pwtd->hwndManager, SRM_REGEX_STARTED, GetCurrentThreadId(), 0);
Expand Down
5 changes: 5 additions & 0 deletions tools/WebcamReportTool/DirectShowUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@
#include <windows.h>
#include <dshow.h>

// disable warning 26471 - Don't use reinterpret_cast. A cast from void* can use static_cast
#pragma warning(push)
#pragma warning(disable: 26471)
#include <wil/com.h>
#pragma warning(push)

#include <winrt/Windows.Foundation.h>

#include <vector>
Expand Down
5 changes: 5 additions & 0 deletions tools/WebcamReportTool/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@
#include <dshow.h>
#include <cguid.h>

// disable warning 26471 - Don't use reinterpret_cast. A cast from void* can use static_cast
#pragma warning(push)
#pragma warning(disable: 26471)
#include <wil/com.h>
#pragma warning(push)

#include <wil/resource.h>

#include <iostream>
Expand Down

0 comments on commit d84a13b

Please sign in to comment.