Code enhancement: prevent from signed integer overflow

Ref:
94154b0f0e (commitcomment-66609009)
This commit is contained in:
Don Ho 2022-02-16 19:13:35 +01:00
parent 51b1c9377c
commit 2df765e189
3 changed files with 5 additions and 5 deletions

View File

@ -3494,7 +3494,7 @@ void FindReplaceDlg::enableProjectCheckmarks()
for (int i = 0; i < 3; i++) for (int i = 0; i < 3; i++)
{ {
UINT s = GetMenuState (hMenu, idm [i], MF_BYCOMMAND); UINT s = GetMenuState (hMenu, idm [i], MF_BYCOMMAND);
if (static_cast<int>(s) != -1) if (s != ((UINT)-1))
{ {
if (s & MF_CHECKED) if (s & MF_CHECKED)
{ {

View File

@ -104,7 +104,7 @@ void ContextMenu::create(HWND hParent, const std::vector<MenuItemUnit> & menuIte
if (mainMenuHandle) if (mainMenuHandle)
{ {
UINT s = ::GetMenuState(mainMenuHandle, item._cmdID, MF_BYCOMMAND); UINT s = ::GetMenuState(mainMenuHandle, item._cmdID, MF_BYCOMMAND);
if (static_cast<int>(s) != -1) if (s != ((UINT)-1))
{ {
bool isEnabled = (s & (MF_DISABLED | MF_GRAYED)) == 0; bool isEnabled = (s & (MF_DISABLED | MF_GRAYED)) == 0;
bool isChecked = (s & (MF_CHECKED)) != 0; bool isChecked = (s & (MF_CHECKED)) != 0;

View File

@ -897,9 +897,9 @@ void WindowsDlg::doClose()
{ {
// Trying to retain sort order. fairly sure there is a much better algorithm for this // Trying to retain sort order. fairly sure there is a much better algorithm for this
vector<int>::iterator kitr = key.begin(); vector<int>::iterator kitr = key.begin();
for (UINT i=0; i<n; ++i, ++kitr) for (UINT i = 0; i < n; ++i, ++kitr)
{ {
if (static_cast<int>(nmdlg.Items[i]) == -1) if (nmdlg.Items[i] == ((UINT)-1))
{ {
int oldVal = _idxMap[*kitr]; int oldVal = _idxMap[*kitr];
_idxMap[*kitr] = -1; _idxMap[*kitr] = -1;
@ -1115,7 +1115,7 @@ void WindowsMenu::initPopupMenu(HMENU hMenu, DocTabView *pTab)
mii.wID = id; mii.wID = id;
UINT state = GetMenuState(hMenu, id, MF_BYCOMMAND); UINT state = GetMenuState(hMenu, id, MF_BYCOMMAND);
if (static_cast<int>(state) == -1) if (state == ((UINT)-1))
InsertMenuItem(hMenu, IDM_WINDOW_WINDOWS, FALSE, &mii); InsertMenuItem(hMenu, IDM_WINDOW_WINDOWS, FALSE, &mii);
else else
SetMenuItemInfo(hMenu, id, FALSE, &mii); SetMenuItemInfo(hMenu, id, FALSE, &mii);