From 2da5c5b393010982047b801c4ad1d0df0bda7d82 Mon Sep 17 00:00:00 2001 From: ozone10 Date: Sat, 10 Sep 2022 14:53:19 +0200 Subject: [PATCH] Code enhancement Fix parentheses, misleading-indentation, sign-compare, some conversion-null warnings. Fix #12139, close #12140 --- PowerEditor/src/EncodingMapper.cpp | 4 ++-- PowerEditor/src/MISC/Common/Common.cpp | 2 +- PowerEditor/src/Notepad_plus.cpp | 16 ++++++++-------- PowerEditor/src/Notepad_plus.h | 2 +- PowerEditor/src/ScintillaComponent/Buffer.cpp | 2 +- PowerEditor/src/ScintillaComponent/Printer.cpp | 6 +++--- .../src/ScintillaComponent/ScintillaEditView.cpp | 10 +++++----- PowerEditor/src/Utf8_16.cpp | 14 +++++++------- .../src/WinControls/Preference/preferenceDlg.cpp | 2 +- PowerEditor/src/WinControls/TreeView/TreeView.h | 2 +- PowerEditor/src/uchardet/JpCntx.cpp | 8 ++++---- PowerEditor/src/uchardet/nsUniversalDetector.cpp | 10 +++++----- 12 files changed, 39 insertions(+), 39 deletions(-) diff --git a/PowerEditor/src/EncodingMapper.cpp b/PowerEditor/src/EncodingMapper.cpp index a59c64da1..f61cb5c58 100644 --- a/PowerEditor/src/EncodingMapper.cpp +++ b/PowerEditor/src/EncodingMapper.cpp @@ -130,8 +130,8 @@ int EncodingMapper::getIndexFromEncoding(int encoding) const int EncodingMapper::getEncodingFromString(const char *encodingAlias) const { - if (isInListA(encodingAlias, "utf-8 utf8")) - return SC_CP_UTF8; + if (isInListA(encodingAlias, "utf-8 utf8")) + return SC_CP_UTF8; size_t nbItem = sizeof(encodings)/sizeof(EncodingUnit); int enc = -1; diff --git a/PowerEditor/src/MISC/Common/Common.cpp b/PowerEditor/src/MISC/Common/Common.cpp index 77b3c7122..b08475f63 100644 --- a/PowerEditor/src/MISC/Common/Common.cpp +++ b/PowerEditor/src/MISC/Common/Common.cpp @@ -333,7 +333,7 @@ const wchar_t * WcharMbcsConvertor::char2wchar(const char * mbcs2Convert, size_t return nullptr; // Do not process empty strings - if (lenMbcs == 0 || lenMbcs == -1 && mbcs2Convert[0] == 0) + if (lenMbcs == 0 || (lenMbcs == -1 && mbcs2Convert[0] == 0)) { _wideCharStr.empty(); return _wideCharStr; diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index 2afce5820..5835fe02a 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -1245,7 +1245,7 @@ void Notepad_plus::wsTabConvert(spaceTab whichWay) char * source = new char[docLength]; if (source == NULL) return; - _pEditView->execute(SCI_GETTEXT, docLength, reinterpret_cast(source)); + _pEditView->execute(SCI_GETTEXT, docLength, reinterpret_cast(source)); if (whichWay == tab2Space) { @@ -5648,7 +5648,7 @@ void Notepad_plus::doSynScorll(HWND whichView) intptr_t pixel; intptr_t mainColumn, subColumn; - if (whichView == _mainEditView.getHSelf()) + if (whichView == _mainEditView.getHSelf()) { if (_syncInfo._isSynScollV) { @@ -5670,9 +5670,9 @@ void Notepad_plus::doSynScorll(HWND whichView) column = mainColumn - _syncInfo._column - subColumn; } pView = &_subEditView; - } - else if (whichView == _subEditView.getHSelf()) - { + } + else if (whichView == _subEditView.getHSelf()) + { if (_syncInfo._isSynScollV) { // Compute for Line @@ -5693,9 +5693,9 @@ void Notepad_plus::doSynScorll(HWND whichView) column = subColumn + _syncInfo._column - mainColumn; } pView = &_mainEditView; - } - else - return; + } + else + return; pView->scroll(column, line); } diff --git a/PowerEditor/src/Notepad_plus.h b/PowerEditor/src/Notepad_plus.h index c2ee8a8ae..5c761a323 100644 --- a/PowerEditor/src/Notepad_plus.h +++ b/PowerEditor/src/Notepad_plus.h @@ -509,7 +509,7 @@ private: } void bookmarkDelete(size_t lineno) const { - if (lineno == -1) + if (lineno == static_cast(-1)) lineno = _pEditView->getCurrentLineNumber(); while (bookmarkPresent(lineno)) _pEditView->execute(SCI_MARKERDELETE, lineno, MARK_BOOKMARK); diff --git a/PowerEditor/src/ScintillaComponent/Buffer.cpp b/PowerEditor/src/ScintillaComponent/Buffer.cpp index 520d503ad..e19ba3693 100644 --- a/PowerEditor/src/ScintillaComponent/Buffer.cpp +++ b/PowerEditor/src/ScintillaComponent/Buffer.cpp @@ -42,7 +42,7 @@ namespace // anonymous { static EolType getEOLFormatForm(const char* const data, size_t length, EolType defvalue = EolType::osdefault) { - assert(length == 0 or data != nullptr && "invalid buffer for getEOLFormatForm()"); + assert(length == 0 || (data != nullptr && "invalid buffer for getEOLFormatForm()")); for (size_t i = 0; i != length; ++i) { diff --git a/PowerEditor/src/ScintillaComponent/Printer.cpp b/PowerEditor/src/ScintillaComponent/Printer.cpp index c82c4b3b0..7fad1c703 100644 --- a/PowerEditor/src/ScintillaComponent/Printer.cpp +++ b/PowerEditor/src/ScintillaComponent/Printer.cpp @@ -329,10 +329,10 @@ size_t Printer::doPrint(bool justDoIt) while (lengthPrinted < lengthDoc) { bool printPage = (!(_pdlg.Flags & PD_PAGENUMS) || - (pageNum >= _pdlg.nFromPage) && (pageNum <= _pdlg.nToPage)); - + ((pageNum >= _pdlg.nFromPage) && (pageNum <= _pdlg.nToPage))); + if (!justDoIt) - printPage = false; + printPage = false; TCHAR pageString[32]; wsprintf(pageString, TEXT("%0d"), pageNum); diff --git a/PowerEditor/src/ScintillaComponent/ScintillaEditView.cpp b/PowerEditor/src/ScintillaComponent/ScintillaEditView.cpp index 690832aea..8a751ad98 100644 --- a/PowerEditor/src/ScintillaComponent/ScintillaEditView.cpp +++ b/PowerEditor/src/ScintillaComponent/ScintillaEditView.cpp @@ -2205,11 +2205,11 @@ bool ScintillaEditView::isCurrentLineFolded() const void ScintillaEditView::fold(size_t line, bool mode) { - auto endStyled = execute(SCI_GETENDSTYLED); - auto len = execute(SCI_GETTEXTLENGTH); + auto endStyled = execute(SCI_GETENDSTYLED); + auto len = execute(SCI_GETTEXTLENGTH); - if (endStyled < len) - execute(SCI_COLOURISE, 0, -1); + if (endStyled < len) + execute(SCI_COLOURISE, 0, -1); intptr_t headerLine; auto level = execute(SCI_GETFOLDLEVEL, line); @@ -2227,7 +2227,7 @@ void ScintillaEditView::fold(size_t line, bool mode) { execute(SCI_TOGGLEFOLD, headerLine); - SCNotification scnN; + SCNotification scnN{}; scnN.nmhdr.code = SCN_FOLDINGSTATECHANGED; scnN.nmhdr.hwndFrom = _hSelf; scnN.nmhdr.idFrom = 0; diff --git a/PowerEditor/src/Utf8_16.cpp b/PowerEditor/src/Utf8_16.cpp index 4b4586867..8e7c4b7f8 100644 --- a/PowerEditor/src/Utf8_16.cpp +++ b/PowerEditor/src/Utf8_16.cpp @@ -635,12 +635,12 @@ void Utf16_Iter::operator++() m_eState = eStart; } else if (m_nCur16 < 0x800) { pushout(static_cast(0xC0 | m_nCur16 >> 6)); - pushout(0x80 | m_nCur16 & 0x3f); + pushout(0x80 | (m_nCur16 & 0x3f)); m_eState = eStart; } else { pushout(0xE0 | (m_nCur16 >> 12)); - pushout(0x80 | (m_nCur16 >> 6) & 0x3f); - pushout(0x80 | m_nCur16 & 0x3f); + pushout(0x80 | ((m_nCur16 >> 6) & 0x3f)); + pushout(0x80 | (m_nCur16 & 0x3f)); m_eState = eStart; } break; @@ -649,10 +649,10 @@ void Utf16_Iter::operator++() if ((m_nCur16 >= 0xDC00) && (m_nCur16 < 0xE000)) { // valid surrogate pair UINT code = 0x10000 + ((m_highSurrogate & 0x3ff) << 10) + (m_nCur16 & 0x3ff); - pushout(0xf0 | (code >> 18) & 0x07); - pushout(0x80 | (code >> 12) & 0x3f); - pushout(0x80 | (code >> 6) & 0x3f); - pushout(0x80 | code & 0x3f); + pushout(0xf0 | ((code >> 18) & 0x07)); + pushout(0x80 | ((code >> 12) & 0x3f)); + pushout(0x80 | ((code >> 6) & 0x3f)); + pushout(0x80 | (code & 0x3f)); } m_eState = eStart; break; diff --git a/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp b/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp index ff013596c..6e7864f03 100644 --- a/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp +++ b/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp @@ -926,7 +926,7 @@ intptr_t CALLBACK EditingSubDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM { svp._currentLineFrameWidth = static_cast(::SendMessage(hCaretLineFrameSlider, TBM_GETPOS, 0, 0)); ::SetDlgItemInt(_hSelf, IDC_CARETLINEFRAME_WIDTH_DISPLAY, svp._currentLineFrameWidth, FALSE); - ::SendMessage(::GetParent(_hParent), NPPM_INTERNAL_CARETLINEFRAME, NULL, svp._currentLineFrameWidth); + ::SendMessage(::GetParent(_hParent), NPPM_INTERNAL_CARETLINEFRAME, 0, svp._currentLineFrameWidth); } return 0; //return zero when handled diff --git a/PowerEditor/src/WinControls/TreeView/TreeView.h b/PowerEditor/src/WinControls/TreeView/TreeView.h index 7831f2baf..741812303 100644 --- a/PowerEditor/src/WinControls/TreeView/TreeView.h +++ b/PowerEditor/src/WinControls/TreeView/TreeView.h @@ -40,7 +40,7 @@ public: virtual void init(HINSTANCE hInst, HWND parent, int treeViewID); virtual void destroy(); - HTREEITEM addItem(const TCHAR *itemName, HTREEITEM hParentItem, int iImage, LPARAM lParam = NULL); + HTREEITEM addItem(const TCHAR *itemName, HTREEITEM hParentItem, int iImage, LPARAM lParam = 0); bool setItemParam(HTREEITEM Item2Set, LPARAM param); LPARAM getItemParam(HTREEITEM Item2Get) const; generic_string getItemDisplayName(HTREEITEM Item2Set) const; diff --git a/PowerEditor/src/uchardet/JpCntx.cpp b/PowerEditor/src/uchardet/JpCntx.cpp index 7da041396..d6a437381 100644 --- a/PowerEditor/src/uchardet/JpCntx.cpp +++ b/PowerEditor/src/uchardet/JpCntx.cpp @@ -195,8 +195,8 @@ float JapaneseContextAnalysis::GetConfidence(void) PRInt32 SJISContextAnalysis::GetOrder(const char* str, PRUint32 *charLen) { //find out current char's byte length - if ((unsigned char)*str >= (unsigned char)0x81 && (unsigned char)*str <= (unsigned char)0x9f || - (unsigned char)*str >= (unsigned char)0xe0 && (unsigned char)*str <= (unsigned char)0xfc ) + if (((unsigned char)*str >= (unsigned char)0x81 && (unsigned char)*str <= (unsigned char)0x9f) || + ((unsigned char)*str >= (unsigned char)0xe0 && (unsigned char)*str <= (unsigned char)0xfc)) *charLen = 2; else *charLen = 1; @@ -213,8 +213,8 @@ PRInt32 EUCJPContextAnalysis::GetOrder(const char* str, PRUint32 *charLen) { //find out current char's byte length if ((unsigned char)*str == (unsigned char)0x8e || - (unsigned char)*str >= (unsigned char)0xa1 && - (unsigned char)*str <= (unsigned char)0xfe) + ((unsigned char)*str >= (unsigned char)0xa1 && + (unsigned char)*str <= (unsigned char)0xfe)) *charLen = 2; else if ((unsigned char)*str == (unsigned char)0x8f) *charLen = 3; diff --git a/PowerEditor/src/uchardet/nsUniversalDetector.cpp b/PowerEditor/src/uchardet/nsUniversalDetector.cpp index dd74243c0..d4f912c60 100644 --- a/PowerEditor/src/uchardet/nsUniversalDetector.cpp +++ b/PowerEditor/src/uchardet/nsUniversalDetector.cpp @@ -130,11 +130,11 @@ nsresult nsUniversalDetector::HandleData(const char* aBuf, PRUint32 aLen) break; } // switch - if (mDetectedCharset) - { - mDone = PR_TRUE; - return NS_OK; - } + if (mDetectedCharset) + { + mDone = PR_TRUE; + return NS_OK; + } } PRUint32 i;