From e76c92913722741a273cf79f598a62bbff15bcde Mon Sep 17 00:00:00 2001 From: Don HO Date: Wed, 3 Aug 2016 21:00:40 +0200 Subject: [PATCH] Safer C++ conversion use static_cast instead of reinterpret_cast --- PowerEditor/src/Notepad_plus.cpp | 2 +- PowerEditor/src/NppBigSwitch.cpp | 8 ++++---- PowerEditor/src/ScitillaComponent/Buffer.h | 2 +- PowerEditor/src/WinControls/AnsiCharPanel/ListView.cpp | 2 +- PowerEditor/src/WinControls/ProjectPanel/TreeView.cpp | 2 +- .../ReadDirectoryChanges/ReadDirectoryChangesPrivate.cpp | 2 +- PowerEditor/src/WinControls/StaticDialog/StaticDialog.cpp | 4 ++-- PowerEditor/src/WinControls/TabBar/TabBar.cpp | 2 +- PowerEditor/src/WinControls/TaskList/TaskList.cpp | 2 +- PowerEditor/src/WinControls/TaskList/TaskListDlg.cpp | 2 +- PowerEditor/src/WinControls/ToolTip/ToolTip.cpp | 2 +- .../VerticalFileSwitcher/VerticalFileSwitcherListView.cpp | 2 +- 12 files changed, 16 insertions(+), 16 deletions(-) diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index 9ea2fbba2..0b6b5a861 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -335,7 +335,7 @@ LRESULT Notepad_plus::init(HWND hwnd) if (_toReduceTabBar) { - HFONT hf = reinterpret_cast(::GetStockObject(DEFAULT_GUI_FONT)); + HFONT hf = static_cast(::GetStockObject(DEFAULT_GUI_FONT)); if (hf) { diff --git a/PowerEditor/src/NppBigSwitch.cpp b/PowerEditor/src/NppBigSwitch.cpp index 16ac711e7..908c081fc 100644 --- a/PowerEditor/src/NppBigSwitch.cpp +++ b/PowerEditor/src/NppBigSwitch.cpp @@ -82,7 +82,7 @@ LRESULT CALLBACK Notepad_plus_Window::Notepad_plus_Proc(HWND hwnd, UINT Message, { // First message we get the ptr of instantiated object // then stock it into GWLP_USERDATA index in order to retrieve afterward - Notepad_plus_Window *pM30ide = reinterpret_cast((reinterpret_cast(lParam))->lpCreateParams); + Notepad_plus_Window *pM30ide = static_cast((reinterpret_cast(lParam))->lpCreateParams); pM30ide->_hSelf = hwnd; ::SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)pM30ide); return TRUE; @@ -524,7 +524,7 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa { case COPYDATA_PARAMS: { - CmdLineParams *cmdLineParam = reinterpret_cast(pCopyData->lpData); // CmdLineParams object from another instance + CmdLineParams *cmdLineParam = static_cast(pCopyData->lpData); // CmdLineParams object from another instance auto cmdLineParamsSize = static_cast(pCopyData->cbData); // CmdLineParams size from another instance if (sizeof(CmdLineParams) == cmdLineParamsSize) // make sure the structure is the same { @@ -544,7 +544,7 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa case COPYDATA_FILENAMESA: { - char *fileNamesA = reinterpret_cast(pCopyData->lpData); + char *fileNamesA = static_cast(pCopyData->lpData); CmdLineParams & cmdLineParams = pNppParam->getCmdLineParams(); WcharMbcsConvertor *wmc = WcharMbcsConvertor::getInstance(); const wchar_t *fileNamesW = wmc->char2wchar(fileNamesA, CP_ACP); @@ -554,7 +554,7 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa case COPYDATA_FILENAMESW: { - wchar_t *fileNamesW = reinterpret_cast(pCopyData->lpData); + wchar_t *fileNamesW = static_cast(pCopyData->lpData); CmdLineParams & cmdLineParams = pNppParam->getCmdLineParams(); loadCommandlineParams(fileNamesW, &cmdLineParams); break; diff --git a/PowerEditor/src/ScitillaComponent/Buffer.h b/PowerEditor/src/ScitillaComponent/Buffer.h index 417063eb5..e0b4f0d24 100644 --- a/PowerEditor/src/ScitillaComponent/Buffer.h +++ b/PowerEditor/src/ScitillaComponent/Buffer.h @@ -32,7 +32,7 @@ class Notepad_plus; class Buffer; typedef Buffer* BufferID; //each buffer has unique ID by which it can be retrieved -#define BUFFER_INVALID (BufferID)0 +#define BUFFER_INVALID reinterpret_cast(0) typedef sptr_t Document; diff --git a/PowerEditor/src/WinControls/AnsiCharPanel/ListView.cpp b/PowerEditor/src/WinControls/AnsiCharPanel/ListView.cpp index e7efe2536..963537c46 100644 --- a/PowerEditor/src/WinControls/AnsiCharPanel/ListView.cpp +++ b/PowerEditor/src/WinControls/AnsiCharPanel/ListView.cpp @@ -64,7 +64,7 @@ void ListView::init(HINSTANCE hInst, HWND parent) } ::SetWindowLongPtr(_hSelf, GWLP_USERDATA, (LONG_PTR)this); - _defaultProc = reinterpret_cast(::SetWindowLongPtr(_hSelf, GWLP_WNDPROC, (LONG_PTR)staticProc)); + _defaultProc = reinterpret_cast(::SetWindowLongPtr(_hSelf, GWLP_WNDPROC, reinterpret_cast(staticProc))); DWORD exStyle = ListView_GetExtendedListViewStyle(_hSelf); exStyle |= LVS_EX_FULLROWSELECT | LVS_EX_BORDERSELECT ; diff --git a/PowerEditor/src/WinControls/ProjectPanel/TreeView.cpp b/PowerEditor/src/WinControls/ProjectPanel/TreeView.cpp index 8149395a2..8adaa8965 100644 --- a/PowerEditor/src/WinControls/ProjectPanel/TreeView.cpp +++ b/PowerEditor/src/WinControls/ProjectPanel/TreeView.cpp @@ -52,7 +52,7 @@ void TreeView::init(HINSTANCE hInst, HWND parent, int treeViewID) TreeView_SetItemHeight(_hSelf, itemHeight); ::SetWindowLongPtr(_hSelf, GWLP_USERDATA, (LONG_PTR)this); - _defaultProc = reinterpret_cast(::SetWindowLongPtr(_hSelf, GWLP_WNDPROC, (LONG_PTR)staticProc)); + _defaultProc = reinterpret_cast(::SetWindowLongPtr(_hSelf, GWLP_WNDPROC, reinterpret_cast(staticProc))); } diff --git a/PowerEditor/src/WinControls/ReadDirectoryChanges/ReadDirectoryChangesPrivate.cpp b/PowerEditor/src/WinControls/ReadDirectoryChanges/ReadDirectoryChangesPrivate.cpp index a8c937a7e..f2d648a15 100644 --- a/PowerEditor/src/WinControls/ReadDirectoryChanges/ReadDirectoryChangesPrivate.cpp +++ b/PowerEditor/src/WinControls/ReadDirectoryChanges/ReadDirectoryChangesPrivate.cpp @@ -112,7 +112,7 @@ VOID CALLBACK CReadChangesRequest::NotificationCompletion( DWORD dwNumberOfBytesTransfered, // number of bytes transferred LPOVERLAPPED lpOverlapped) // I/O information buffer { - CReadChangesRequest* pBlock = reinterpret_cast(lpOverlapped->hEvent); + CReadChangesRequest* pBlock = static_cast(lpOverlapped->hEvent); if (dwErrorCode == ERROR_OPERATION_ABORTED) { diff --git a/PowerEditor/src/WinControls/StaticDialog/StaticDialog.cpp b/PowerEditor/src/WinControls/StaticDialog/StaticDialog.cpp index da766a6fe..d939e4bff 100644 --- a/PowerEditor/src/WinControls/StaticDialog/StaticDialog.cpp +++ b/PowerEditor/src/WinControls/StaticDialog/StaticDialog.cpp @@ -118,14 +118,14 @@ HGLOBAL StaticDialog::makeRTLResource(int dialogID, DLGTEMPLATE **ppMyDlgTemplat if (!hDlgTemplate) return NULL; - DLGTEMPLATE *pDlgTemplate = reinterpret_cast(::LockResource(hDlgTemplate)); + DLGTEMPLATE *pDlgTemplate = static_cast(::LockResource(hDlgTemplate)); if (!pDlgTemplate) return NULL; // Duplicate Dlg Template resource unsigned long sizeDlg = ::SizeofResource(_hInst, hDialogRC); HGLOBAL hMyDlgTemplate = ::GlobalAlloc(GPTR, sizeDlg); - *ppMyDlgTemplate = reinterpret_cast(::GlobalLock(hMyDlgTemplate)); + *ppMyDlgTemplate = static_cast(::GlobalLock(hMyDlgTemplate)); ::memcpy(*ppMyDlgTemplate, pDlgTemplate, sizeDlg); diff --git a/PowerEditor/src/WinControls/TabBar/TabBar.cpp b/PowerEditor/src/WinControls/TabBar/TabBar.cpp index f92a75d32..1a16f2437 100644 --- a/PowerEditor/src/WinControls/TabBar/TabBar.cpp +++ b/PowerEditor/src/WinControls/TabBar/TabBar.cpp @@ -323,7 +323,7 @@ void TabBarPlus::init(HINSTANCE hInst, HWND parent, bool isVertical, bool isTrad ++_nbCtrl; ::SetWindowLongPtr(_hSelf, GWLP_USERDATA, (LONG_PTR)this); - _tabBarDefaultProc = reinterpret_cast(::SetWindowLongPtr(_hSelf, GWLP_WNDPROC, (LONG_PTR)TabBarPlus_Proc)); + _tabBarDefaultProc = reinterpret_cast(::SetWindowLongPtr(_hSelf, GWLP_WNDPROC, reinterpret_cast(TabBarPlus_Proc))); } LOGFONT LogFont; diff --git a/PowerEditor/src/WinControls/TaskList/TaskList.cpp b/PowerEditor/src/WinControls/TaskList/TaskList.cpp index 1d1f81ae7..fcf69d177 100644 --- a/PowerEditor/src/WinControls/TaskList/TaskList.cpp +++ b/PowerEditor/src/WinControls/TaskList/TaskList.cpp @@ -69,7 +69,7 @@ void TaskList::init(HINSTANCE hInst, HWND parent, HIMAGELIST hImaLst, int nbItem } ::SetWindowLongPtr(_hSelf, GWLP_USERDATA, (LONG_PTR)this); - _defaultProc = reinterpret_cast(::SetWindowLongPtr(_hSelf, GWLP_WNDPROC, (LONG_PTR)staticProc)); + _defaultProc = reinterpret_cast(::SetWindowLongPtr(_hSelf, GWLP_WNDPROC, reinterpret_cast(staticProc))); DWORD exStyle = ListView_GetExtendedListViewStyle(_hSelf); exStyle |= LVS_EX_FULLROWSELECT | LVS_EX_BORDERSELECT ; diff --git a/PowerEditor/src/WinControls/TaskList/TaskListDlg.cpp b/PowerEditor/src/WinControls/TaskList/TaskListDlg.cpp index dddcd0387..eb33787a5 100644 --- a/PowerEditor/src/WinControls/TaskList/TaskListDlg.cpp +++ b/PowerEditor/src/WinControls/TaskList/TaskListDlg.cpp @@ -116,7 +116,7 @@ INT_PTR CALLBACK TaskListDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM lP { case LVN_GETDISPINFO: { - LV_ITEM &lvItem = reinterpret_cast((LV_DISPINFO FAR *)lParam)->item; + LV_ITEM &lvItem = reinterpret_cast(reinterpret_cast(lParam))->item; TaskLstFnStatus & fileNameStatus = _taskListInfo._tlfsLst[lvItem.iItem]; diff --git a/PowerEditor/src/WinControls/ToolTip/ToolTip.cpp b/PowerEditor/src/WinControls/ToolTip/ToolTip.cpp index a4a892e41..9e77ccd89 100644 --- a/PowerEditor/src/WinControls/ToolTip/ToolTip.cpp +++ b/PowerEditor/src/WinControls/ToolTip/ToolTip.cpp @@ -46,7 +46,7 @@ void ToolTip::init(HINSTANCE hInst, HWND hParent) } ::SetWindowLongPtr(_hSelf, GWLP_USERDATA, (LONG_PTR)this); - _defaultProc = reinterpret_cast(::SetWindowLongPtr(_hSelf, GWLP_WNDPROC, (LONG_PTR)staticWinProc)); + _defaultProc = reinterpret_cast(::SetWindowLongPtr(_hSelf, GWLP_WNDPROC, reinterpret_cast(staticWinProc))); } } diff --git a/PowerEditor/src/WinControls/VerticalFileSwitcher/VerticalFileSwitcherListView.cpp b/PowerEditor/src/WinControls/VerticalFileSwitcher/VerticalFileSwitcherListView.cpp index b1b03150d..e63100e86 100644 --- a/PowerEditor/src/WinControls/VerticalFileSwitcher/VerticalFileSwitcherListView.cpp +++ b/PowerEditor/src/WinControls/VerticalFileSwitcher/VerticalFileSwitcherListView.cpp @@ -67,7 +67,7 @@ void VerticalFileSwitcherListView::init(HINSTANCE hInst, HWND parent, HIMAGELIST } ::SetWindowLongPtr(_hSelf, GWLP_USERDATA, (LONG_PTR)this); - _defaultProc = reinterpret_cast(::SetWindowLongPtr(_hSelf, GWLP_WNDPROC, (LONG_PTR)staticProc)); + _defaultProc = reinterpret_cast(::SetWindowLongPtr(_hSelf, GWLP_WNDPROC, reinterpret_cast(staticProc))); ListView_SetExtendedListViewStyle(_hSelf, LVS_EX_FULLROWSELECT | LVS_EX_BORDERSELECT | LVS_EX_INFOTIP); ListView_SetItemCountEx(_hSelf, 50, LVSICF_NOSCROLL);