Skip to content

Commit

Permalink
Fix clang-tidy [bugprone-multi-level-implicit-pointer-conversion] w…
Browse files Browse the repository at this point in the history
…arnings.
  • Loading branch information
zufuliu committed Dec 25, 2023
1 parent 1f3f202 commit e0082bb
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 36 deletions.
12 changes: 6 additions & 6 deletions metapath/src/Dlapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ int DirList_Fill(HWND hwnd, LPCWSTR lpszDir, DWORD grfFlags, LPCWSTR lpszFileSpe
#if defined(__cplusplus)
if (S_OK == lpsfDesktop->ParseDisplayName(hwnd, nullptr, wszDir, &chParsed, &pidl, &dwAttributes)) {
// Bind pidl to IShellFolder
if (S_OK == lpsfDesktop->BindToObject(pidl, nullptr, IID_IShellFolder, (void **)(&lpsf))) {
if (S_OK == lpsfDesktop->BindToObject(pidl, nullptr, IID_IShellFolder, reinterpret_cast<void **>(&lpsf))) {
// Create an Enumeration object for lpsf
LPENUMIDLIST lpe = nullptr;
if (S_OK == lpsf->EnumObjects(hwnd, grfFlags, &lpe)) {
Expand Down Expand Up @@ -319,7 +319,7 @@ DWORD WINAPI DirList_IconThread(LPVOID lpParam) {
// Get IShellIcon
IShellIcon *lpshi;
#if defined(__cplusplus)
lpdl->lpsf->QueryInterface(IID_IShellIcon, (void **)(&lpshi));
lpdl->lpsf->QueryInterface(IID_IShellIcon, reinterpret_cast<void **>(&lpshi));
#else
lpdl->lpsf->lpVtbl->QueryInterface(lpdl->lpsf, &IID_IShellIcon, (void **)(&lpshi));
#endif
Expand Down Expand Up @@ -645,7 +645,7 @@ bool DirList_PropertyDlg(HWND hwnd, int iItem) {
LPCONTEXTMENU lpcm;

#if defined(__cplusplus)
if (S_OK == lplvid->lpsf->GetUIObjectOf(GetParent(hwnd), 1, (PCUITEMID_CHILD_ARRAY)(&lplvid->pidl), IID_IContextMenu, nullptr, (void **)(&lpcm))) {
if (S_OK == lplvid->lpsf->GetUIObjectOf(GetParent(hwnd), 1, (PCUITEMID_CHILD_ARRAY)(&lplvid->pidl), IID_IContextMenu, nullptr, reinterpret_cast<void **>(&lpcm))) {
CMINVOKECOMMANDINFO cmi;
cmi.cbSize = sizeof(CMINVOKECOMMANDINFO);
cmi.fMask = 0;
Expand Down Expand Up @@ -715,7 +715,7 @@ void DirList_DoDragDrop(HWND hwnd, LPARAM lParam) {
LPLV_ITEMDATA lplvid = (LPLV_ITEMDATA)lvi.lParam;
LPDATAOBJECT lpdo;
#if defined(__cplusplus)
if (SUCCEEDED(lplvid->lpsf->GetUIObjectOf(GetParent(hwnd), 1, (PCUITEMID_CHILD_ARRAY)(&lplvid->pidl), IID_IDataObject, nullptr, (void **)(&lpdo)))) {
if (SUCCEEDED(lplvid->lpsf->GetUIObjectOf(GetParent(hwnd), 1, (PCUITEMID_CHILD_ARRAY)(&lplvid->pidl), IID_IDataObject, nullptr, reinterpret_cast<void **>(&lpdo)))) {
LPDROPSOURCE lpds = (LPDROPSOURCE)CreateDropSource();
DWORD dwEffect;

Expand Down Expand Up @@ -939,7 +939,7 @@ int DriveBox_Fill(HWND hwnd) {
// Bind pidl to IShellFolder
LPSHELLFOLDER lpsf; // Workspace == CSIDL_DRIVES
#if defined(__cplusplus)
if (S_OK == lpsfDesktop->BindToObject(pidl, nullptr, IID_IShellFolder, (void **)(&lpsf))) {
if (S_OK == lpsfDesktop->BindToObject(pidl, nullptr, IID_IShellFolder, reinterpret_cast<void **>(&lpsf))) {
// Create an Enumeration object for lpsf
const DWORD grfFlags = SHCONTF_FOLDERS;
LPENUMIDLIST lpe;
Expand Down Expand Up @@ -1150,7 +1150,7 @@ bool DriveBox_PropertyDlg(HWND hwnd) {
LPCONTEXTMENU lpcm;

#if defined(__cplusplus)
if (S_OK == lpdcid->lpsf->GetUIObjectOf(GetParent(hwnd), 1, (PCUITEMID_CHILD_ARRAY)(&lpdcid->pidl), IID_IContextMenu, nullptr, (void **)(&lpcm))) {
if (S_OK == lpdcid->lpsf->GetUIObjectOf(GetParent(hwnd), 1, (PCUITEMID_CHILD_ARRAY)(&lpdcid->pidl), IID_IContextMenu, nullptr, reinterpret_cast<void **>(&lpcm))) {
CMINVOKECOMMANDINFO cmi;
cmi.cbSize = sizeof(CMINVOKECOMMANDINFO);
cmi.fMask = 0;
Expand Down
12 changes: 6 additions & 6 deletions metapath/src/Helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -1288,10 +1288,10 @@ bool PathGetLnkPath(LPCWSTR pszLnkFile, LPWSTR pszResPath) {
tchPath[0] = L'\0';

#if defined(__cplusplus)
if (SUCCEEDED(CoCreateInstance(IID_IShellLink, nullptr, CLSCTX_INPROC_SERVER, IID_IShellLink, (LPVOID *)(&psl)))) {
if (SUCCEEDED(CoCreateInstance(IID_IShellLink, nullptr, CLSCTX_INPROC_SERVER, IID_IShellLink, reinterpret_cast<LPVOID *>(&psl)))) {
IPersistFile *ppf;

if (SUCCEEDED(psl->QueryInterface(IID_IPersistFile, (void **)(&ppf)))) {
if (SUCCEEDED(psl->QueryInterface(IID_IPersistFile, reinterpret_cast<void **>(&ppf)))) {
if (SUCCEEDED(ppf->Load(pszLnkFile, STGM_READ))) {
hr = psl->GetPath(tchPath, COUNTOF(tchPath), nullptr, 0);
}
Expand Down Expand Up @@ -1347,10 +1347,10 @@ bool PathCreateLnk(LPCWSTR pszLnkDir, LPCWSTR pszPath) {
bool bSucceeded = false;

#if defined(__cplusplus)
if (SUCCEEDED(CoCreateInstance(IID_IShellLink, nullptr, CLSCTX_INPROC_SERVER, IID_IShellLink, (LPVOID *)(&psl)))) {
if (SUCCEEDED(CoCreateInstance(IID_IShellLink, nullptr, CLSCTX_INPROC_SERVER, IID_IShellLink, reinterpret_cast<LPVOID *>(&psl)))) {
IPersistFile *ppf;

if (SUCCEEDED(psl->QueryInterface(IID_IPersistFile, (void **)(&ppf)))) {
if (SUCCEEDED(psl->QueryInterface(IID_IPersistFile, reinterpret_cast<void **>(&ppf)))) {
psl->SetPath(pszPath);

if (SUCCEEDED(ppf->Save(tchLnkFileName, TRUE))) {
Expand Down Expand Up @@ -1788,7 +1788,7 @@ bool History_Add(PHISTORY ph, LPCWSTR pszNew) {
LocalFree(ph->psz[0]);
}

memmove(ph->psz, ph->psz + 1, (HISTORY_ITEMS - 1) * sizeof(WCHAR *));
memmove(NP2_void_pointer(ph->psz), NP2_void_pointer(ph->psz + 1), (HISTORY_ITEMS - 1) * sizeof(WCHAR *));
}

ph->psz[ph->iCurItem] = StrDup(pszNew);
Expand Down Expand Up @@ -1862,7 +1862,7 @@ void MRU_Init(LPMRULIST pmru, LPCWSTR pszRegKey, int iFlags) {
pmru->iSize = 0;
pmru->iFlags = iFlags;
pmru->szRegKey = pszRegKey;
memset(pmru->pszItems, 0, sizeof(pmru->pszItems));
memset(NP2_void_pointer(pmru->pszItems), 0, sizeof(pmru->pszItems));
MRU_Load(pmru);
}

Expand Down
7 changes: 7 additions & 0 deletions metapath/src/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ typedef _Bool bool;
#define NP2_static_assert(expr) _STATIC_ASSERT(expr)
#endif

// suppress clang-tidy [bugprone-multi-level-implicit-pointer-conversion] warning
#if defined(__cplusplus)
#define NP2_void_pointer(expr) (reinterpret_cast<void *>(expr))
#else
#define NP2_void_pointer(expr) ((void *)(expr))
#endif

#if (defined(__GNUC__) || defined(__clang__)) && !defined(__cplusplus)
// https://stackoverflow.com/questions/19452971/array-size-macro-that-rejects-pointers
// trigger error for pointer: GCC: void value not ignored as it ought to be. Clang: invalid operands to binary expression.
Expand Down
10 changes: 5 additions & 5 deletions src/Dlapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ int DirList_Fill(HWND hwnd, LPCWSTR lpszDir, DWORD grfFlags, LPCWSTR lpszFileSpe
#if defined(__cplusplus)
if (S_OK == lpsfDesktop->ParseDisplayName(hwnd, nullptr, wszDir, &chParsed, &pidl, &dwAttributes)) {
// Bind pidl to IShellFolder
if (S_OK == lpsfDesktop->BindToObject(pidl, nullptr, IID_IShellFolder, (void **)(&lpsf))) {
if (S_OK == lpsfDesktop->BindToObject(pidl, nullptr, IID_IShellFolder, reinterpret_cast<void **>(&lpsf))) {
// Create an Enumeration object for lpsf
LPENUMIDLIST lpe = nullptr;
if (S_OK == lpsf->EnumObjects(hwnd, grfFlags, &lpe)) {
Expand Down Expand Up @@ -333,7 +333,7 @@ DWORD WINAPI DirList_IconThread(LPVOID lpParam) {
// Get IShellIcon
IShellIcon *lpshi;
#if defined(__cplusplus)
lpdl->lpsf->QueryInterface(IID_IShellIcon, (void **)(&lpshi));
lpdl->lpsf->QueryInterface(IID_IShellIcon, reinterpret_cast<void **>(&lpshi));
#else
lpdl->lpsf->lpVtbl->QueryInterface(lpdl->lpsf, &IID_IShellIcon, (void **)(&lpshi));
#endif
Expand Down Expand Up @@ -659,7 +659,7 @@ bool DirList_PropertyDlg(HWND hwnd, int iItem) {
LPCONTEXTMENU lpcm;

#if defined(__cplusplus)
if (S_OK == lplvid->lpsf->GetUIObjectOf(GetParent(hwnd), 1, (PCUITEMID_CHILD_ARRAY)(&lplvid->pidl), IID_IContextMenu, nullptr, (void **)(&lpcm))) {
if (S_OK == lplvid->lpsf->GetUIObjectOf(GetParent(hwnd), 1, (PCUITEMID_CHILD_ARRAY)(&lplvid->pidl), IID_IContextMenu, nullptr, reinterpret_cast<void **>(&lpcm))) {
CMINVOKECOMMANDINFO cmi;
cmi.cbSize = sizeof(CMINVOKECOMMANDINFO);
cmi.fMask = 0;
Expand Down Expand Up @@ -890,7 +890,7 @@ int DriveBox_Fill(HWND hwnd) {
// Bind pidl to IShellFolder
LPSHELLFOLDER lpsf; // Workspace == CSIDL_DRIVES
#if defined(__cplusplus)
if (S_OK == lpsfDesktop->BindToObject(pidl, nullptr, IID_IShellFolder, (void **)(&lpsf))) {
if (S_OK == lpsfDesktop->BindToObject(pidl, nullptr, IID_IShellFolder, reinterpret_cast<void **>(&lpsf))) {
// Create an Enumeration object for lpsf
const DWORD grfFlags = SHCONTF_FOLDERS;
LPENUMIDLIST lpe;
Expand Down Expand Up @@ -1105,7 +1105,7 @@ bool DriveBox_PropertyDlg(HWND hwnd) {
LPCONTEXTMENU lpcm;

#if defined(__cplusplus)
if (S_OK == lpdcid->lpsf->GetUIObjectOf(GetParent(hwnd), 1, (PCUITEMID_CHILD_ARRAY)(&lpdcid->pidl), IID_IContextMenu, nullptr, (void **)(&lpcm))) {
if (S_OK == lpdcid->lpsf->GetUIObjectOf(GetParent(hwnd), 1, (PCUITEMID_CHILD_ARRAY)(&lpdcid->pidl), IID_IContextMenu, nullptr, reinterpret_cast<void **>(&lpcm))) {
CMINVOKECOMMANDINFO cmi;
cmi.cbSize = sizeof(CMINVOKECOMMANDINFO);
cmi.fMask = 0;
Expand Down
16 changes: 8 additions & 8 deletions src/Helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -1801,10 +1801,10 @@ bool PathGetLnkPath(LPCWSTR pszLnkFile, LPWSTR pszResPath) {
tchPath[0] = L'\0';

#if defined(__cplusplus)
if (SUCCEEDED(CoCreateInstance(IID_IShellLink, nullptr, CLSCTX_INPROC_SERVER, IID_IShellLink, (LPVOID *)(&psl)))) {
if (SUCCEEDED(CoCreateInstance(IID_IShellLink, nullptr, CLSCTX_INPROC_SERVER, IID_IShellLink, reinterpret_cast<LPVOID *>(&psl)))) {
IPersistFile *ppf;

if (SUCCEEDED(psl->QueryInterface(IID_IPersistFile, (void **)(&ppf)))) {
if (SUCCEEDED(psl->QueryInterface(IID_IPersistFile, reinterpret_cast<void **>(&ppf)))) {
if (SUCCEEDED(ppf->Load(pszLnkFile, STGM_READ))) {
hr = psl->GetPath(tchPath, COUNTOF(tchPath), nullptr, 0);
}
Expand Down Expand Up @@ -1897,10 +1897,10 @@ bool PathCreateDeskLnk(LPCWSTR pszDocument) {
IShellLink *psl;
bool bSucceeded = false;
#if defined(__cplusplus)
if (SUCCEEDED(CoCreateInstance(IID_IShellLink, nullptr, CLSCTX_INPROC_SERVER, IID_IShellLink, (LPVOID *)(&psl)))) {
if (SUCCEEDED(CoCreateInstance(IID_IShellLink, nullptr, CLSCTX_INPROC_SERVER, IID_IShellLink, reinterpret_cast<LPVOID *>(&psl)))) {
IPersistFile *ppf;

if (SUCCEEDED(psl->QueryInterface(IID_IPersistFile, (void **)(&ppf)))) {
if (SUCCEEDED(psl->QueryInterface(IID_IPersistFile, reinterpret_cast<void **>(&ppf)))) {
psl->SetPath(tchExeFile);
psl->SetArguments(tchArguments);
psl->SetDescription(tchDescription);
Expand Down Expand Up @@ -1959,10 +1959,10 @@ bool PathCreateFavLnk(LPCWSTR pszName, LPCWSTR pszTarget, LPCWSTR pszDir) {
IShellLink *psl;
bool bSucceeded = false;
#if defined(__cplusplus)
if (SUCCEEDED(CoCreateInstance(IID_IShellLink, nullptr, CLSCTX_INPROC_SERVER, IID_IShellLink, (LPVOID *)(&psl)))) {
if (SUCCEEDED(CoCreateInstance(IID_IShellLink, nullptr, CLSCTX_INPROC_SERVER, IID_IShellLink, reinterpret_cast<LPVOID *>(&psl)))) {
IPersistFile *ppf;

if (SUCCEEDED(psl->QueryInterface(IID_IPersistFile, (void **)(&ppf)))) {
if (SUCCEEDED(psl->QueryInterface(IID_IPersistFile, reinterpret_cast<void **>(&ppf)))) {
psl->SetPath(pszTarget);
if (SUCCEEDED(ppf->Save(tchLnkFileName, TRUE))) {
bSucceeded = true;
Expand Down Expand Up @@ -2348,7 +2348,7 @@ void MRU_Init(LPMRULIST pmru, LPCWSTR pszRegKey, int iFlags) {
pmru->iSize = 0;
pmru->iFlags = iFlags;
pmru->szRegKey = pszRegKey;
memset(pmru->pszItems, 0, sizeof(pmru->pszItems));
memset(NP2_void_pointer(pmru->pszItems), 0, sizeof(pmru->pszItems));
MRU_Load(pmru);
}

Expand Down Expand Up @@ -2588,7 +2588,7 @@ HBITMAP BitmapCache_Get(BitmapCache *cache, LPCWSTR path) {
ImageList_GetIconSize(imageList, &width, &height);
const BITMAPINFO bmi = { {sizeof(BITMAPINFOHEADER), width, -height, 1, 32, BI_RGB, 0, 0, 0, 0, 0}, {{ 0, 0, 0, 0 }} };
hbmp = CreateDIBSection(NULL, &bmi, DIB_RGB_COLORS, NULL, NULL, 0);
HBITMAP oldBitmap = (HBITMAP)SelectObject(bitmapDC, hbmp);
HBITMAP oldBitmap = SelectBitmap(bitmapDC, hbmp);
ImageList_Draw(imageList, iIcon, bitmapDC, 0, 0, ILD_TRANSPARENT);
SelectBitmap(bitmapDC, oldBitmap);
DeleteDC(bitmapDC);
Expand Down
15 changes: 7 additions & 8 deletions src/Notepad2.c
Original file line number Diff line number Diff line change
Expand Up @@ -1949,7 +1949,7 @@ LRESULT MsgCreate(HWND hwnd, WPARAM wParam, LPARAM lParam) {
DragAcceptFiles(hwnd, TRUE);

// File MRU
int flags = MRUFlags_FilePath | (((int)flagRelativeFileMRU) * MRUFlags_RelativePath) | (((int)flagPortableMyDocs) * MRUFlags_PortableMyDocs);
const int flags = MRUFlags_FilePath | (((int)flagRelativeFileMRU) * MRUFlags_RelativePath) | (((int)flagPortableMyDocs) * MRUFlags_PortableMyDocs);
MRU_Init(&mruFile, MRU_KEY_RECENT_FILES, flags);
MRU_Init(&mruFind, MRU_KEY_RECENT_FIND, MRUFlags_QuoteValue);
MRU_Init(&mruReplace, MRU_KEY_RECENT_REPLACE, MRUFlags_QuoteValue);
Expand Down Expand Up @@ -5344,16 +5344,15 @@ LRESULT MsgNotify(HWND hwnd, WPARAM wParam, LPARAM lParam) {
HMENU subMenu = NULL;
if (lpTbNotify->iItem == IDT_FILE_OPEN) {
NP2_static_assert(IDM_RECENT_HISTORY_START + MRU_MAXITEMS == IDM_RECENT_HISTORY_END);
const int count = mruFile.iSize;
if (count <= 0) {
if (mruFile.iSize <= 0) {
return TBDDRET_TREATPRESSED;
}
hmenu = subMenu = CreatePopupMenu();
BitmapCache_StartUse(&bitmapCache);
MENUITEMINFO mii;
mii.cbSize = sizeof(MENUITEMINFO);
mii.fMask = MIIM_ID | MIIM_STRING | MIIM_BITMAP;
for (int i = 0; i < count; i++) {
for (int i = 0; i < mruFile.iSize; i++) {
LPCWSTR path = mruFile.pszItems[i];
HBITMAP hbmp = BitmapCache_Get(&bitmapCache, path);
mii.wID = i + IDM_RECENT_HISTORY_START;
Expand Down Expand Up @@ -7216,7 +7215,7 @@ void UpdateStatusbar(void) {
tchSelChar, tchSelByte, tchLinesSelected, tchMatchesCount);

LPCWSTR items[StatusItem_ItemCount];
memset((void *)(&items[0]), 0, StatusItem_Lexer * sizeof(LPCWSTR));
memset(NP2_void_pointer(&items[0]), 0, StatusItem_Lexer * sizeof(LPCWSTR));
LPWSTR start = itemText;
UINT index = 0;
for (int i = 0; i < len; i++) {
Expand All @@ -7232,7 +7231,7 @@ void UpdateStatusbar(void) {
}

items[index] = start;
memcpy((void *)(&items[StatusItem_Lexer]), &cachedStatusItem.pszLexerName, (StatusItem_Zoom - StatusItem_Lexer)*sizeof(LPCWSTR));
memcpy(NP2_void_pointer(&items[StatusItem_Lexer]), NP2_void_pointer(&cachedStatusItem.pszLexerName), (StatusItem_Zoom - StatusItem_Lexer)*sizeof(LPCWSTR));
items[StatusItem_Zoom] = cachedStatusItem.tchZoom;
items[StatusItem_DocSize] = tchDocSize;

Expand Down Expand Up @@ -8784,7 +8783,7 @@ void AutoSave_Stop(BOOL keepBackup) {
}

autoSaveCount = 0;
memset(autoSavePathList, 0, sizeof(LPWSTR) * AllAutoSaveCount);
memset(NP2_void_pointer(autoSavePathList), 0, sizeof(LPWSTR) * AllAutoSaveCount);
}
}

Expand Down Expand Up @@ -8937,7 +8936,7 @@ void AutoSave_DoWork(FileSaveFlag saveFlag) {
}
LocalFree(old);
}
memmove(autoSavePathList, autoSavePathList + 1, (AllAutoSaveCount - 1) * sizeof(LPWSTR));
memmove(NP2_void_pointer(autoSavePathList), NP2_void_pointer(autoSavePathList + 1), (AllAutoSaveCount - 1) * sizeof(LPWSTR));
autoSavePathList[AllAutoSaveCount - 1] = NULL;
--autoSaveCount;
}
Expand Down
6 changes: 3 additions & 3 deletions src/Styles.c
Original file line number Diff line number Diff line change
Expand Up @@ -3884,8 +3884,8 @@ static HTREEITEM Style_AddAllLexerToTreeView(HWND hwndTV, bool withStyles, bool

// all general schemes
PEDITLEXER generalLex[GENERAL_LEXER_COUNT];
memcpy(generalLex, pLexArray + LEXER_INDEX_GENERAL, sizeof(generalLex));
qsort(generalLex, GENERAL_LEXER_COUNT, sizeof(PEDITLEXER), CmpEditLexerByName);
memcpy(NP2_void_pointer(generalLex), NP2_void_pointer(pLexArray + LEXER_INDEX_GENERAL), sizeof(generalLex));
qsort(NP2_void_pointer(generalLex), GENERAL_LEXER_COUNT, sizeof(PEDITLEXER), CmpEditLexerByName);

iLexer = 0;
while (iLexer < GENERAL_LEXER_COUNT) {
Expand Down Expand Up @@ -4852,7 +4852,7 @@ static void Style_GetFavoriteSchemesFromTreeView(HWND hwndTV, HTREEITEM hFavorit
wch[len] = L'\0';
}

qsort(pLexArray + LEXER_INDEX_GENERAL, GENERAL_LEXER_COUNT, sizeof(PEDITLEXER), CmpEditLexerByOrder);
qsort(NP2_void_pointer(pLexArray + LEXER_INDEX_GENERAL), GENERAL_LEXER_COUNT, sizeof(PEDITLEXER), CmpEditLexerByOrder);
}

//=============================================================================
Expand Down
7 changes: 7 additions & 0 deletions src/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ typedef _Bool bool;
#define NP2_static_assert(expr) _STATIC_ASSERT(expr)
#endif

// suppress clang-tidy [bugprone-multi-level-implicit-pointer-conversion] warning
#if defined(__cplusplus)
#define NP2_void_pointer(expr) (reinterpret_cast<void *>(expr))
#else
#define NP2_void_pointer(expr) ((void *)(expr))
#endif

#if (defined(__GNUC__) || defined(__clang__)) && !defined(__cplusplus)
// https://stackoverflow.com/questions/19452971/array-size-macro-that-rejects-pointers
// trigger error for pointer: GCC: void value not ignored as it ought to be. Clang: invalid operands to binary expression.
Expand Down

0 comments on commit e0082bb

Please sign in to comment.