From 94154b0f0e281b4bbfad9c59f8d01c9dff305c12 Mon Sep 17 00:00:00 2001 From: Don Ho Date: Wed, 9 Feb 2022 20:06:59 +0100 Subject: [PATCH] Code enhancement: Fix comparison of different signs integers --- PowerEditor/src/MISC/RegExt/regExtDlg.cpp | 2 +- PowerEditor/src/Notepad_plus.cpp | 16 +++++----- PowerEditor/src/Parameters.cpp | 2 +- .../src/ScintillaComponent/FindReplaceDlg.cpp | 4 +-- .../ScintillaComponent/ScintillaEditView.cpp | 6 ++-- .../ScintillaComponent/UserDefineDialog.cpp | 30 +++++++++---------- .../src/ScintillaComponent/UserDefineDialog.h | 2 +- .../WinControls/ColourPicker/WordStyleDlg.cpp | 12 ++++---- .../WinControls/ContextMenu/ContextMenu.cpp | 2 +- PowerEditor/src/WinControls/Grid/BabyGrid.cpp | 16 +++++----- .../WinControls/Preference/preferenceDlg.cpp | 8 ++--- PowerEditor/src/WinControls/TabBar/TabBar.cpp | 4 +-- .../VerticalFileSwitcher.cpp | 4 +-- .../src/WinControls/WindowsDlg/WindowsDlg.cpp | 14 +++++---- .../src/WinControls/WindowsDlg/WindowsDlg.h | 2 +- .../src/WinControls/shortcut/shortcut.cpp | 12 ++++---- PowerEditor/src/lastRecentFileList.cpp | 2 +- 17 files changed, 68 insertions(+), 70 deletions(-) diff --git a/PowerEditor/src/MISC/RegExt/regExtDlg.cpp b/PowerEditor/src/MISC/RegExt/regExtDlg.cpp index 2ec2d7151..fa5fd1ed2 100644 --- a/PowerEditor/src/MISC/RegExt/regExtDlg.cpp +++ b/PowerEditor/src/MISC/RegExt/regExtDlg.cpp @@ -258,7 +258,7 @@ intptr_t CALLBACK RegExtDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM lPa { const size_t itemNameLen = 32; TCHAR itemName[itemNameLen + 1] = { '\0' }; - auto lbTextLen = ::SendDlgItemMessage(_hSelf, LOWORD(wParam), LB_GETTEXTLEN, i, 0); + size_t lbTextLen = ::SendDlgItemMessage(_hSelf, LOWORD(wParam), LB_GETTEXTLEN, i, 0); if (lbTextLen > itemNameLen) return TRUE; diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index b8c4987a9..721f4d654 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -3601,7 +3601,7 @@ size_t Notepad_plus::getSelectedCharNumber(UniMode u) for (size_t j = line1; j <= line2; ++j) { size_t stpos = _pEditView->execute(SCI_GETLINESELSTARTPOSITION, j); - if (stpos != INVALID_POSITION) + if (static_cast(stpos) != INVALID_POSITION) { size_t endpos = _pEditView->execute(SCI_GETLINESELENDPOSITION, j); for (size_t pos = stpos; pos < endpos; ++pos) @@ -5803,30 +5803,30 @@ bool Notepad_plus::dumpFiles(const TCHAR * outdir, const TCHAR * fileprefix) void Notepad_plus::drawTabbarColoursFromStylerArray() { Style *stActText = getStyleFromName(TABBAR_ACTIVETEXT); - if (stActText && stActText->_fgColor != -1) + if (stActText && static_cast(stActText->_fgColor) != -1) TabBarPlus::setColour(stActText->_fgColor, TabBarPlus::activeText); Style *stActfocusTop = getStyleFromName(TABBAR_ACTIVEFOCUSEDINDCATOR); - if (stActfocusTop && stActfocusTop->_fgColor != -1) + if (stActfocusTop && static_cast(stActfocusTop->_fgColor) != -1) TabBarPlus::setColour(stActfocusTop->_fgColor, TabBarPlus::activeFocusedTop); Style *stActunfocusTop = getStyleFromName(TABBAR_ACTIVEUNFOCUSEDINDCATOR); - if (stActunfocusTop && stActunfocusTop->_fgColor != -1) + if (stActunfocusTop && static_cast(stActunfocusTop->_fgColor) != -1) TabBarPlus::setColour(stActunfocusTop->_fgColor, TabBarPlus::activeUnfocusedTop); Style *stInact = getStyleFromName(TABBAR_INACTIVETEXT); - if (stInact && stInact->_fgColor != -1) + if (stInact && static_cast(stInact->_fgColor) != -1) TabBarPlus::setColour(stInact->_fgColor, TabBarPlus::inactiveText); - if (stInact && stInact->_bgColor != -1) + if (stInact && static_cast(stInact->_bgColor) != -1) TabBarPlus::setColour(stInact->_bgColor, TabBarPlus::inactiveBg); } void Notepad_plus::drawDocumentMapColoursFromStylerArray() { Style* docMap = getStyleFromName(VIEWZONE_DOCUMENTMAP); - if (docMap && docMap->_fgColor != -1) + if (docMap && static_cast(docMap->_fgColor) != -1) ViewZoneDlg::setColour(docMap->_fgColor, ViewZoneDlg::ViewZoneColorIndex::focus); - if (docMap && docMap->_bgColor != -1) + if (docMap && static_cast(docMap->_bgColor) != -1) ViewZoneDlg::setColour(docMap->_bgColor, ViewZoneDlg::ViewZoneColorIndex::frost); } diff --git a/PowerEditor/src/Parameters.cpp b/PowerEditor/src/Parameters.cpp index df96583a0..6372454e6 100644 --- a/PowerEditor/src/Parameters.cpp +++ b/PowerEditor/src/Parameters.cpp @@ -630,7 +630,7 @@ int base64ToAscii(char *dest, const char *base64Str) uc2 = (UCHAR)base64IndexArray[base64Str[j+2]]; uc3 = (UCHAR)base64IndexArray[base64Str[j+3]]; - if ((uc0 == -1) || (uc1 == -1) || (uc2 == -1) || (uc3 == -1)) + if ((static_cast(uc0) == -1) || (static_cast(uc1) == -1) || (static_cast(uc2) == -1) || (static_cast(uc3) == -1)) return -1; if (base64Str[j+2] == '=') // && (uc3 == '=') diff --git a/PowerEditor/src/ScintillaComponent/FindReplaceDlg.cpp b/PowerEditor/src/ScintillaComponent/FindReplaceDlg.cpp index b15c0f984..2bba4b41d 100644 --- a/PowerEditor/src/ScintillaComponent/FindReplaceDlg.cpp +++ b/PowerEditor/src/ScintillaComponent/FindReplaceDlg.cpp @@ -499,7 +499,7 @@ bool Finder::notify(SCNotification *notification) ::SendMessage(_scintView.getHSelf(), WM_LBUTTONUP, 0, 0); size_t pos = notification->position; - if (pos == INVALID_POSITION) + if (static_cast(pos) == INVALID_POSITION) pos = _scintView.execute(SCI_GETLINEENDPOSITION, notification->line); _scintView.execute(SCI_SETSEL, pos, pos); @@ -3494,7 +3494,7 @@ void FindReplaceDlg::enableProjectCheckmarks() for (int i = 0; i < 3; i++) { UINT s = GetMenuState (hMenu, idm [i], MF_BYCOMMAND); - if (s != -1) + if (static_cast(s) != -1) { if (s & MF_CHECKED) { diff --git a/PowerEditor/src/ScintillaComponent/ScintillaEditView.cpp b/PowerEditor/src/ScintillaComponent/ScintillaEditView.cpp index 197fb7d8e..655c4808b 100644 --- a/PowerEditor/src/ScintillaComponent/ScintillaEditView.cpp +++ b/PowerEditor/src/ScintillaComponent/ScintillaEditView.cpp @@ -418,7 +418,7 @@ LRESULT ScintillaEditView::scintillaNew_Proc(HWND hwnd, UINT Message, WPARAM wPa if (selectSize == 0) return 0; - if (selectSize + 1 > sizeof(smallTextBuffer)) + if (static_cast(selectSize + 1) > sizeof(smallTextBuffer)) selectedStr = new char[selectSize + 1]; getText(selectedStr, range.cpMin, range.cpMax); @@ -1940,14 +1940,14 @@ void ScintillaEditView::getCurrentFoldStates(std::vector & lineStateVect do { contractedFoldHeaderLine = execute(SCI_CONTRACTEDFOLDNEXT, contractedFoldHeaderLine); - if (contractedFoldHeaderLine != -1) + if (static_cast(contractedFoldHeaderLine) != -1) { //-- Store contracted line lineStateVector.push_back(contractedFoldHeaderLine); //-- Start next search with next line ++contractedFoldHeaderLine; } - } while (contractedFoldHeaderLine != -1); + } while (static_cast(contractedFoldHeaderLine) != -1); } void ScintillaEditView::syncFoldStateWith(const std::vector & lineStateVectorNew) diff --git a/PowerEditor/src/ScintillaComponent/UserDefineDialog.cpp b/PowerEditor/src/ScintillaComponent/UserDefineDialog.cpp index 3ed6eb83b..bb2c35f71 100644 --- a/PowerEditor/src/ScintillaComponent/UserDefineDialog.cpp +++ b/PowerEditor/src/ScintillaComponent/UserDefineDialog.cpp @@ -37,7 +37,7 @@ GlobalMappers & globalMappper() return gm; } -void convertTo(TCHAR *dest, int destLen, const TCHAR *toConvert, TCHAR *prefix) +void convertTo(TCHAR *dest, int destLen, const TCHAR *toConvert, const TCHAR *prefix) { bool inGroup = false; int index = lstrlen(dest); @@ -526,7 +526,6 @@ void CommentStyleDialog::setKeywords2List(int id) newList[0] = '\0'; TCHAR* buffer = new TCHAR[max_char]; buffer[0] = '\0'; - TCHAR intBuffer[10] = {'0', 0}; const int list[] = { IDC_COMMENTLINE_OPEN_EDIT, @@ -536,11 +535,11 @@ void CommentStyleDialog::setKeywords2List(int id) IDC_COMMENT_CLOSE_EDIT }; - for (auto i = 0; i < sizeof(list)/sizeof(int); ++i) + for (size_t i = 0; i < sizeof(list)/sizeof(int); ++i) { - generic_itoa(i, intBuffer+1, 10); + wstring intStr = std::to_wstring(i); ::GetDlgItemText(_hSelf, list[i], buffer, max_char); - convertTo(newList, max_char, buffer, intBuffer); + convertTo(newList, max_char, buffer, intStr.c_str()); } wcscpy_s(_pUserLang->_keywordLists[index], newList); @@ -549,7 +548,7 @@ void CommentStyleDialog::setKeywords2List(int id) } } -void CommentStyleDialog::retrieve(TCHAR *dest, const TCHAR *toRetrieve, TCHAR *prefix) const +void CommentStyleDialog::retrieve(TCHAR *dest, const TCHAR *toRetrieve, const TCHAR *prefix) const { int j = 0; bool begin2Copy = false; @@ -589,7 +588,6 @@ void CommentStyleDialog::updateDlg() { TCHAR* buffer = new TCHAR[max_char]; buffer[0] = '\0'; - TCHAR intBuffer[10] = {'0', 0}; const int list[] = { IDC_COMMENTLINE_OPEN_EDIT, @@ -599,10 +597,10 @@ void CommentStyleDialog::updateDlg() IDC_COMMENT_CLOSE_EDIT }; - for (int i=0; i_keywordLists[SCE_USER_KWLIST_COMMENTS], intBuffer); + wstring intStr = std::to_wstring(i); + retrieve(buffer, _pUserLang->_keywordLists[SCE_USER_KWLIST_COMMENTS], intStr.c_str()); ::SendDlgItemMessage(_hSelf, list[i], WM_SETTEXT, 0, reinterpret_cast(buffer)); } @@ -659,7 +657,7 @@ void SymbolsStyleDialog::updateDlg() }; TCHAR intBuffer[10] = {'0', 0}; - for (int i = 0; i < sizeof(list)/sizeof(int); ++i) + for (int i = 0; static_cast(i) < sizeof(list)/sizeof(int); ++i) { if (i < 10) generic_itoa(i, intBuffer + 1, 10); @@ -853,7 +851,7 @@ void SymbolsStyleDialog::setKeywords2List(int id) IDC_DELIMITER8_BOUNDARYCLOSE_EDIT }; - for (int i = 0; i < sizeof(list)/sizeof(int); ++i) + for (int i = 0; static_cast(i) < sizeof(list)/sizeof(int); ++i) { if (i < 10) generic_itoa(i, intBuffer+1, 10); @@ -1223,7 +1221,7 @@ intptr_t CALLBACK UserDefineDialog::run_dlgProc(UINT message, WPARAM wParam, LPA const size_t langNameLen = 256; TCHAR langName[langNameLen + 1]; auto cbTextLen = ::SendDlgItemMessage(_hSelf, IDC_LANGNAME_COMBO, CB_GETLBTEXTLEN, i, 0); - if (cbTextLen > langNameLen) + if (static_cast(cbTextLen) > langNameLen) return TRUE; ::SendDlgItemMessage(_hSelf, IDC_LANGNAME_COMBO, CB_GETLBTEXT, i, reinterpret_cast(langName)); @@ -1252,7 +1250,7 @@ intptr_t CALLBACK UserDefineDialog::run_dlgProc(UINT message, WPARAM wParam, LPA const size_t langNameLen = 256; TCHAR langName[langNameLen + 1]; auto cbTextLen = ::SendDlgItemMessage(_hSelf, IDC_LANGNAME_COMBO, CB_GETLBTEXTLEN, i, 0); - if (cbTextLen > langNameLen) + if (static_cast(cbTextLen) > langNameLen) return TRUE; ::SendDlgItemMessage(_hSelf, IDC_LANGNAME_COMBO, CB_GETLBTEXT, i, reinterpret_cast(langName)); @@ -1755,7 +1753,7 @@ intptr_t CALLBACK StylerDlg::dlgProc(HWND hwnd, UINT message, WPARAM wParam, LPA // for the font size combo HWND hFontSizeCombo = ::GetDlgItem(hwnd, IDC_STYLER_COMBO_FONT_SIZE); - for (int j = 0 ; j < int(sizeof(fontSizeStrs))/(3*sizeof(TCHAR)) ; ++j) + for (size_t j = 0 ; j < int(sizeof(fontSizeStrs))/(3*sizeof(TCHAR)) ; ++j) ::SendMessage(hFontSizeCombo, CB_ADDSTRING, 0, reinterpret_cast(fontSizeStrs[j])); TCHAR size[10]; @@ -1879,7 +1877,7 @@ intptr_t CALLBACK StylerDlg::dlgProc(HWND hwnd, UINT message, WPARAM wParam, LPA const size_t intStrLen = 3; TCHAR intStr[intStrLen]; auto lbTextLen = ::SendDlgItemMessage(hwnd, LOWORD(wParam), CB_GETLBTEXTLEN, i, 0); - if (lbTextLen > intStrLen - 1) + if (static_cast(lbTextLen) > intStrLen - 1) return TRUE; ::SendDlgItemMessage(hwnd, LOWORD(wParam), CB_GETLBTEXT, i, reinterpret_cast(intStr)); diff --git a/PowerEditor/src/ScintillaComponent/UserDefineDialog.h b/PowerEditor/src/ScintillaComponent/UserDefineDialog.h index 21f4835cb..882c72cd6 100644 --- a/PowerEditor/src/ScintillaComponent/UserDefineDialog.h +++ b/PowerEditor/src/ScintillaComponent/UserDefineDialog.h @@ -284,7 +284,7 @@ protected : intptr_t CALLBACK run_dlgProc(UINT Message, WPARAM wParam, LPARAM lParam); void setKeywords2List(int id); private : - void retrieve(TCHAR *dest, const TCHAR *toRetrieve, TCHAR *prefix) const; + void retrieve(TCHAR *dest, const TCHAR *toRetrieve, const TCHAR *prefix) const; }; class SymbolsStyleDialog : public SharedParametersDialog diff --git a/PowerEditor/src/WinControls/ColourPicker/WordStyleDlg.cpp b/PowerEditor/src/WinControls/ColourPicker/WordStyleDlg.cpp index cdc00a920..57e82fe61 100644 --- a/PowerEditor/src/WinControls/ColourPicker/WordStyleDlg.cpp +++ b/PowerEditor/src/WinControls/ColourPicker/WordStyleDlg.cpp @@ -120,7 +120,7 @@ intptr_t CALLBACK WordStyleDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM } ::SendMessage(_hSwitch2ThemeCombo, CB_SETCURSEL, _currentThemeIndex, 0); - for (int i = 0 ; i < sizeof(fontSizeStrs)/(3*sizeof(TCHAR)) ; ++i) + for (size_t i = 0 ; i < sizeof(fontSizeStrs)/(3*sizeof(TCHAR)) ; ++i) ::SendMessage(_hFontSizeCombo, CB_ADDSTRING, 0, reinterpret_cast(fontSizeStrs[i])); const std::vector & fontlist = (NppParameters::getInstance()).getFontList(); @@ -572,7 +572,7 @@ int WordStyleDlg::whichTabColourIndex() const size_t styleNameLen = 128; TCHAR styleName[styleNameLen + 1] = { '\0' }; auto lbTextLen = ::SendDlgItemMessage(_hSelf, IDC_STYLES_LIST, LB_GETTEXTLEN, i, 0); - if (lbTextLen > styleNameLen) + if (static_cast(lbTextLen) > styleNameLen) return -1; ::SendDlgItemMessage(_hSelf, IDC_STYLES_LIST, LB_GETTEXT, i, reinterpret_cast(styleName)); @@ -601,7 +601,7 @@ bool WordStyleDlg::isDocumentMapStyle() constexpr size_t styleNameLen = 128; TCHAR styleName[styleNameLen + 1] = { '\0' }; const auto lbTextLen = ::SendDlgItemMessage(_hSelf, IDC_STYLES_LIST, LB_GETTEXTLEN, i, 0); - if (lbTextLen > styleNameLen) + if (static_cast(lbTextLen) > styleNameLen) return false; ::SendDlgItemMessage(_hSelf, IDC_STYLES_LIST, LB_GETTEXT, i, reinterpret_cast(styleName)); @@ -641,7 +641,7 @@ void WordStyleDlg::updateFontSize() TCHAR intStr[intStrLen]; auto lbTextLen = ::SendMessage(_hFontSizeCombo, CB_GETLBTEXTLEN, iFontSizeSel, 0); - if (lbTextLen >= intStrLen) + if (static_cast(lbTextLen) >= intStrLen) return; ::SendMessage(_hFontSizeCombo, CB_GETLBTEXT, iFontSizeSel, reinterpret_cast(intStr)); @@ -844,7 +844,7 @@ void WordStyleDlg::setVisualFromStyleList() if (i == LB_ERR) return; auto lbTextLen = ::SendDlgItemMessage(_hSelf, IDC_LANGUAGES_LIST, LB_GETTEXTLEN, i, 0); - if (lbTextLen > strLen) + if (static_cast(lbTextLen) > strLen) return; ::SendDlgItemMessage(_hSelf, IDC_LANGUAGES_LIST, LB_GETTEXT, i, reinterpret_cast(str)); @@ -855,7 +855,7 @@ void WordStyleDlg::setVisualFromStyleList() const size_t styleNameLen = 64; TCHAR styleName[styleNameLen + 1] = { '\0' }; lbTextLen = ::SendDlgItemMessage(_hSelf, IDC_STYLES_LIST, LB_GETTEXTLEN, i, 0); - if (lbTextLen > styleNameLen) + if (static_cast(lbTextLen) > styleNameLen) return; ::SendDlgItemMessage(_hSelf, IDC_STYLES_LIST, LB_GETTEXT, i, reinterpret_cast(styleName)); wcscat_s(str, TEXT(" : ")); diff --git a/PowerEditor/src/WinControls/ContextMenu/ContextMenu.cpp b/PowerEditor/src/WinControls/ContextMenu/ContextMenu.cpp index 69dca743e..5adb7cd59 100644 --- a/PowerEditor/src/WinControls/ContextMenu/ContextMenu.cpp +++ b/PowerEditor/src/WinControls/ContextMenu/ContextMenu.cpp @@ -104,7 +104,7 @@ void ContextMenu::create(HWND hParent, const std::vector & menuIte if (mainMenuHandle) { UINT s = ::GetMenuState(mainMenuHandle, item._cmdID, MF_BYCOMMAND); - if (s != -1) + if (static_cast(s) != -1) { bool isEnabled = (s & (MF_DISABLED | MF_GRAYED)) == 0; bool isChecked = (s & (MF_CHECKED)) != 0; diff --git a/PowerEditor/src/WinControls/Grid/BabyGrid.cpp b/PowerEditor/src/WinControls/Grid/BabyGrid.cpp index d31c6ac89..5791147dd 100644 --- a/PowerEditor/src/WinControls/Grid/BabyGrid.cpp +++ b/PowerEditor/src/WinControls/Grid/BabyGrid.cpp @@ -1559,7 +1559,7 @@ LRESULT CALLBACK GridProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { //it was found, get the text, modify text delete it from list, add modified to list auto lbTextLen = ::SendMessage(BGHS[SelfIndex].hlist1, LB_GETTEXTLEN, FindResult, 0); - if (lbTextLen > bufferLen) + if (static_cast(lbTextLen) > bufferLen) return TRUE; SendMessage(BGHS[SelfIndex].hlist1, LB_GETTEXT, FindResult, reinterpret_cast(buffer)); @@ -1687,7 +1687,7 @@ LRESULT CALLBACK GridProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) if(j>0) { auto lbTextLen = ::SendMessage(BGHS[SelfIndex].hlist1, LB_GETTEXTLEN, j-1, 0); - if (lbTextLen > bufferLen) + if (static_cast(lbTextLen) > bufferLen) return TRUE; SendMessage(BGHS[SelfIndex].hlist1, LB_GETTEXT, j - 1, reinterpret_cast(buffer)); buffer[5]=0x00; @@ -1790,7 +1790,7 @@ LRESULT CALLBACK GridProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { //it was found, get it auto lbTextLen = ::SendMessage(BGHS[SelfIndex].hlist1, LB_GETTEXTLEN, FindResult, 0); - if (lbTextLen > bufferLen) + if (static_cast(lbTextLen) > bufferLen) return TRUE; SendMessage(BGHS[SelfIndex].hlist1, LB_GETTEXT, FindResult, reinterpret_cast(buffer)); switch (buffer[10]) // no need to call BGM_GETPROTECTION separately for this @@ -1949,7 +1949,7 @@ LRESULT CALLBACK GridProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { //it was found, get it auto lbTextLen = ::SendMessage(BGHS[SelfIndex].hlist1, LB_GETTEXTLEN, FindResult, 0); - if (lbTextLen > bufferLen) + if (static_cast(lbTextLen) > bufferLen) return TRUE; SendMessage(BGHS[SelfIndex].hlist1, LB_GETTEXT, FindResult, reinterpret_cast(buffer)); switch (buffer[11]) @@ -1981,7 +1981,7 @@ LRESULT CALLBACK GridProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { //it was found, get it auto lbTextLen = ::SendMessage(BGHS[SelfIndex].hlist1, LB_GETTEXTLEN, FindResult, 0); - if (lbTextLen > bufferLen) + if (static_cast(lbTextLen) > bufferLen) return TRUE; SendMessage(BGHS[SelfIndex].hlist1, LB_GETTEXT, FindResult, reinterpret_cast(buffer)); switch (buffer[10]) @@ -3197,7 +3197,7 @@ int BinarySearchListBox(HWND lbhWnd,TCHAR* searchtext) //is it the head? auto lbTextLen = ::SendMessage(lbhWnd, LB_GETTEXTLEN, head, 0); - if (lbTextLen > bufLen) + if (static_cast(lbTextLen) > bufLen) return 0; SendMessage(lbhWnd, LB_GETTEXT, head, reinterpret_cast(headtext)); @@ -3221,7 +3221,7 @@ int BinarySearchListBox(HWND lbhWnd,TCHAR* searchtext) //is it the tail? lbTextLen = ::SendMessage(lbhWnd, LB_GETTEXTLEN, tail, 0); - if (lbTextLen > bufLen) + if (static_cast(lbTextLen) > bufLen) return 0; SendMessage(lbhWnd, LB_GETTEXT, tail, reinterpret_cast(tailtext)); tailtext[9] = 0x00; @@ -3248,7 +3248,7 @@ int BinarySearchListBox(HWND lbhWnd,TCHAR* searchtext) { finger = head + ((tail - head) / 2); lbTextLen = ::SendMessage(lbhWnd, LB_GETTEXTLEN, finger, 0); - if (lbTextLen > bufLen) + if (static_cast(lbTextLen) > bufLen) return 0; SendMessage(lbhWnd, LB_GETTEXT, finger, reinterpret_cast(tbuffer)); tbuffer[9] = 0x00; diff --git a/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp b/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp index b70882cb0..0b5225b31 100644 --- a/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp +++ b/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp @@ -323,7 +323,7 @@ bool PreferenceDlg::setListSelection(size_t currentSel) const TCHAR selStr[selStrLenMax + 1]; auto lbTextLen = ::SendMessage(_hSelf, LB_GETTEXTLEN, currentSel, 0); - if (lbTextLen > selStrLenMax) + if (static_cast(lbTextLen) > selStrLenMax) return false; ::SendDlgItemMessage(_hSelf, IDC_LIST_DLGTITLE, LB_GETTEXT, currentSel, reinterpret_cast(selStr)); @@ -2580,13 +2580,13 @@ intptr_t CALLBACK LanguageSubDlg::run_dlgProc(UINT message, WPARAM wParam, LPARA pDestLst = &_langList; } size_t iRemove = ::SendDlgItemMessage(_hSelf, list2Remove, LB_GETCURSEL, 0, 0); - if (iRemove == -1) + if (static_cast(iRemove) == -1) return TRUE; const size_t sL = 31; TCHAR s[sL + 1]; auto lbTextLen = ::SendDlgItemMessage(_hSelf, list2Remove, LB_GETTEXTLEN, iRemove, 0); - if (lbTextLen > sL) + if (static_cast(lbTextLen) > sL) return TRUE; ::SendDlgItemMessage(_hSelf, list2Remove, LB_GETTEXT, iRemove, reinterpret_cast(s)); @@ -3207,7 +3207,7 @@ intptr_t CALLBACK PrintSubDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM) TCHAR intStr[intStrLen]; auto lbTextLen = ::SendDlgItemMessage(_hSelf, LOWORD(wParam), CB_GETLBTEXTLEN, iSel, 0); - if (lbTextLen >= intStrLen) + if (static_cast(lbTextLen) >= intStrLen) return TRUE; ::SendDlgItemMessage(_hSelf, LOWORD(wParam), CB_GETLBTEXT, iSel, reinterpret_cast(intStr)); diff --git a/PowerEditor/src/WinControls/TabBar/TabBar.cpp b/PowerEditor/src/WinControls/TabBar/TabBar.cpp index 6ea5723bf..618762d91 100644 --- a/PowerEditor/src/WinControls/TabBar/TabBar.cpp +++ b/PowerEditor/src/WinControls/TabBar/TabBar.cpp @@ -160,7 +160,7 @@ void TabBar::activateAt(int index) const void TabBar::deletItemAt(size_t index) { - if ((index == _nbItem-1)) + if (index == _nbItem - 1) { //prevent invisible tabs. If last visible tab is removed, other tabs are put in view but not redrawn //Therefore, scroll one tab to the left if only one tab visible @@ -912,7 +912,7 @@ LRESULT TabBarPlus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPara int nSelTab = TabCtrl_GetCurSel(hwnd); for (int i = 0; i < nTabs; ++i) { - DRAWITEMSTRUCT dis = { ODT_TAB, id, (UINT)i, ODA_DRAWENTIRE, ODS_DEFAULT, hwnd, hdc }; + DRAWITEMSTRUCT dis = { ODT_TAB, id, (UINT)i, ODA_DRAWENTIRE, ODS_DEFAULT, hwnd, hdc, {}, 0 }; TabCtrl_GetItemRect(hwnd, i, &dis.rcItem); if (i == nFocusTab) diff --git a/PowerEditor/src/WinControls/VerticalFileSwitcher/VerticalFileSwitcher.cpp b/PowerEditor/src/WinControls/VerticalFileSwitcher/VerticalFileSwitcher.cpp index 18e87a637..644eb0a21 100644 --- a/PowerEditor/src/WinControls/VerticalFileSwitcher/VerticalFileSwitcher.cpp +++ b/PowerEditor/src/WinControls/VerticalFileSwitcher/VerticalFileSwitcher.cpp @@ -396,12 +396,12 @@ void VerticalFileSwitcher::updateHeaderArrow() if (_lastSortingDirection == SORT_DIRECTION_UP) { - lvc.fmt = lvc.fmt | HDF_SORTUP & ~HDF_SORTDOWN; + lvc.fmt = (lvc.fmt | HDF_SORTUP) & ~HDF_SORTDOWN; SendMessage(hListView, LVM_SETCOLUMN, _lastSortingColumn, reinterpret_cast(&lvc)); } else if (_lastSortingDirection == SORT_DIRECTION_DOWN) { - lvc.fmt = lvc.fmt & ~HDF_SORTUP | HDF_SORTDOWN; + lvc.fmt = (lvc.fmt & ~HDF_SORTUP) | HDF_SORTDOWN; SendMessage(hListView, LVM_SETCOLUMN, _lastSortingColumn, reinterpret_cast(&lvc)); } else if (_lastSortingDirection == SORT_DIRECTION_NONE) diff --git a/PowerEditor/src/WinControls/WindowsDlg/WindowsDlg.cpp b/PowerEditor/src/WinControls/WindowsDlg/WindowsDlg.cpp index d6d179c55..c8c748742 100644 --- a/PowerEditor/src/WinControls/WindowsDlg/WindowsDlg.cpp +++ b/PowerEditor/src/WinControls/WindowsDlg/WindowsDlg.cpp @@ -44,7 +44,7 @@ using namespace std; static const TCHAR *readonlyString = TEXT(" [Read Only]"); const UINT WDN_NOTIFY = RegisterWindowMessage(TEXT("WDN_NOTIFY")); - +/* inline static DWORD GetStyle(HWND hWnd) { return (DWORD)GetWindowLongPtr(hWnd, GWL_STYLE); } @@ -70,7 +70,7 @@ inline static BOOL ModifyStyleEx(HWND hWnd, DWORD dwRemove, DWORD dwAdd) { ::SetWindowLongPtr(hWnd, GWL_EXSTYLE, dwNewStyle); return TRUE; } - +*/ struct NumericStringEquivalence { @@ -133,10 +133,10 @@ struct NumericStringEquivalence struct BufferEquivalent { NumericStringEquivalence _strequiv; - DocTabView *_pTab; + DocTabView* _pTab; int _iColumn; bool _reverse; - BufferEquivalent(DocTabView *pTab, int iColumn, bool reverse) + BufferEquivalent(DocTabView* pTab, int iColumn, bool reverse) : _pTab(pTab), _iColumn(iColumn), _reverse(reverse) {} @@ -807,6 +807,8 @@ void WindowsDlg::fitColumnsToSize() void WindowsDlg::resetSelection() { + assert(_pTab != nullptr); + auto curSel = _pTab->getCurrentTabIndex(); int pos = 0; for (vector::iterator itr = _idxMap.begin(), end = _idxMap.end(); itr != end; ++itr, ++pos) @@ -897,7 +899,7 @@ void WindowsDlg::doClose() vector::iterator kitr = key.begin(); for (UINT i=0; i(nmdlg.Items[i]) == -1) { int oldVal = _idxMap[*kitr]; _idxMap[*kitr] = -1; @@ -1113,7 +1115,7 @@ void WindowsMenu::initPopupMenu(HMENU hMenu, DocTabView *pTab) mii.wID = id; UINT state = GetMenuState(hMenu, id, MF_BYCOMMAND); - if (state == -1) + if (static_cast(state) == -1) InsertMenuItem(hMenu, IDM_WINDOW_WINDOWS, FALSE, &mii); else SetMenuItemInfo(hMenu, id, FALSE, &mii); diff --git a/PowerEditor/src/WinControls/WindowsDlg/WindowsDlg.h b/PowerEditor/src/WinControls/WindowsDlg/WindowsDlg.h index 18162faae..3e0cf79ae 100644 --- a/PowerEditor/src/WinControls/WindowsDlg/WindowsDlg.h +++ b/PowerEditor/src/WinControls/WindowsDlg/WindowsDlg.h @@ -85,7 +85,7 @@ protected : static RECT _lastKnownLocation; SIZE _szMinButton = {}; SIZE _szMinListCtrl = {}; - DocTabView *_pTab = nullptr; + DocTabView* _pTab = nullptr; std::vector _idxMap; int _currentColumn = -1; int _lastSort = -1; diff --git a/PowerEditor/src/WinControls/shortcut/shortcut.cpp b/PowerEditor/src/WinControls/shortcut/shortcut.cpp index f3a62188f..90040c052 100644 --- a/PowerEditor/src/WinControls/shortcut/shortcut.cpp +++ b/PowerEditor/src/WinControls/shortcut/shortcut.cpp @@ -27,11 +27,9 @@ using namespace std; -const int KEY_STR_LEN = 16; - struct KeyIDNAME { - const TCHAR * name; - UCHAR id; + const TCHAR * name = nullptr; + UCHAR id = 0; }; KeyIDNAME namedKeyArray[] = { @@ -161,8 +159,8 @@ void Shortcut::setName(const TCHAR * menuName, const TCHAR * shortcutName) { lstrcpyn(_menuName, menuName, nameLenMax); TCHAR const * name = shortcutName ? shortcutName : menuName; - int i = 0, j = 0; - while (name[j] != 0 && i < (nameLenMax-1)) + size_t i = 0, j = 0; + while (name[j] != 0 && i < (nameLenMax - 1)) { if (name[j] != '&') { @@ -274,7 +272,7 @@ void getKeyStrFromVal(UCHAR keyVal, generic_string & str) { str = TEXT(""); bool found = false; - int i; + size_t i; for (i = 0; i < nbKeys; ++i) { if (keyVal == namedKeyArray[i].id) diff --git a/PowerEditor/src/lastRecentFileList.cpp b/PowerEditor/src/lastRecentFileList.cpp index 9777e598b..29a74834b 100644 --- a/PowerEditor/src/lastRecentFileList.cpp +++ b/PowerEditor/src/lastRecentFileList.cpp @@ -38,7 +38,7 @@ void LastRecentFileList::initMenu(HMENU hMenu, int idBase, int posBase, Accelera _pAccelerator = pAccelerator; _nativeLangEncoding = NPP_CP_WIN_1252; - for (int i = 0 ; i < sizeof(_idFreeArray) ; ++i) + for (size_t i = 0 ; i < sizeof(_idFreeArray) ; ++i) _idFreeArray[i] = true; }