From 1dd48be2871b0245d5dfb86f061b2138e559a48d Mon Sep 17 00:00:00 2001 From: Rainer Kottenhoff Date: Wed, 30 Jan 2019 11:21:33 +0100 Subject: [PATCH] + cln: CppCheck (v1.86) clean code suggestions --- minipath/src/Dlapi.c | 2 +- scionigmo/OnigmoRegExEngine.cxx | 4 ++-- src/Dialogs.c | 32 +++++++++++++++----------------- src/Dlapi.c | 2 +- src/Edit.c | 2 +- src/Encoding.c | 2 +- src/Notepad3.c | 2 +- src/Styles.c | 26 ++++++++++++-------------- 8 files changed, 34 insertions(+), 38 deletions(-) diff --git a/minipath/src/Dlapi.c b/minipath/src/Dlapi.c index 8524b04f5..27aa9c2fa 100644 --- a/minipath/src/Dlapi.c +++ b/minipath/src/Dlapi.c @@ -1346,7 +1346,7 @@ BOOL DriveBox_SelectDrive(HWND hwnd,LPCWSTR lpszPath) } // Don't select anything - SendMessage(hwnd,CB_SETCURSEL,(WPARAM)-1,0); + SendMessage(hwnd,CB_SETCURSEL,(WPARAM)1,0); return FALSE; } diff --git a/scionigmo/OnigmoRegExEngine.cxx b/scionigmo/OnigmoRegExEngine.cxx index fbc543e8a..0eb925b60 100644 --- a/scionigmo/OnigmoRegExEngine.cxx +++ b/scionigmo/OnigmoRegExEngine.cxx @@ -251,7 +251,7 @@ Sci::Position OnigmoRegExEngine::FindText(Document* doc, Sci::Position minPos, S ONIG_OPTION_ON(onigmoOptions, (rangeEnd != docLen) ? ONIG_OPTION_NOTEOL : ONIG_OPTION_NONE); std::string sPattern(pattern); - std::string const sRegExprStrg = translateRegExpr(sPattern, word, wordStart, doc->eolMode, onigmoOptions); + std::string const & sRegExprStrg = translateRegExpr(sPattern, word, wordStart, doc->eolMode, onigmoOptions); bool const bReCompile = (m_RegExpr == nullptr) || (m_CmplOptions != onigmoOptions) || (m_RegExprStrg.compare(sRegExprStrg) != 0); @@ -360,7 +360,7 @@ const char* OnigmoRegExEngine::SubstituteByPosition(Document* doc, const char* t return nullptr; } std::string sText(text, *length); - std::string const rawReplStrg = convertReplExpr(sText); + std::string const & rawReplStrg = convertReplExpr(sText); m_SubstBuffer.clear(); diff --git a/src/Dialogs.c b/src/Dialogs.c index 1ab60140a..900f85920 100644 --- a/src/Dialogs.c +++ b/src/Dialogs.c @@ -508,28 +508,26 @@ INT_PTR CALLBACK AboutDlgProc(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam { case WM_INITDIALOG: { - { - if (Globals.hDlgIcon) { SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)Globals.hDlgIcon); } + if (Globals.hDlgIcon) { SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)Globals.hDlgIcon); } - SetDlgItemText(hwnd, IDC_VERSION, MKWCS(VERSION_FILEVERSION_LONG)); + SetDlgItemText(hwnd, IDC_VERSION, MKWCS(VERSION_FILEVERSION_LONG)); - if (hFontTitle) { DeleteObject(hFontTitle); } + if (hFontTitle) { DeleteObject(hFontTitle); } - if (NULL == (hFontTitle = (HFONT)SendDlgItemMessage(hwnd, IDC_VERSION, WM_GETFONT, 0, 0))) { - hFontTitle = GetStockObject(DEFAULT_GUI_FONT); - } - - LOGFONT lf; - GetObject(hFontTitle, sizeof(LOGFONT), &lf); - lf.lfWeight = FW_BOLD; - lf.lfWidth = ScaleIntFontSize(8); - lf.lfHeight = ScaleIntFontSize(22); - // lf.lfQuality = ANTIALIASED_QUALITY; - hFontTitle = CreateFontIndirect(&lf); - - SendDlgItemMessage(hwnd, IDC_VERSION, WM_SETFONT, (WPARAM)hFontTitle, true); + if (NULL == (hFontTitle = (HFONT)SendDlgItemMessage(hwnd, IDC_VERSION, WM_GETFONT, 0, 0))) { + hFontTitle = GetStockObject(DEFAULT_GUI_FONT); } + LOGFONT lf; + GetObject(hFontTitle, sizeof(LOGFONT), &lf); + lf.lfWeight = FW_BOLD; + lf.lfWidth = ScaleIntFontSize(8); + lf.lfHeight = ScaleIntFontSize(22); + // lf.lfQuality = ANTIALIASED_QUALITY; + hFontTitle = CreateFontIndirect(&lf); + + SendDlgItemMessage(hwnd, IDC_VERSION, WM_SETFONT, (WPARAM)hFontTitle, true); + SetDlgItemText(hwnd, IDC_SCI_VERSION, VERSION_SCIVERSION); SetDlgItemText(hwnd, IDC_COPYRIGHT, VERSION_LEGALCOPYRIGHT); SetDlgItemText(hwnd, IDC_AUTHORNAME, VERSION_AUTHORNAME); diff --git a/src/Dlapi.c b/src/Dlapi.c index 2f8e4794d..909c7211c 100644 --- a/src/Dlapi.c +++ b/src/Dlapi.c @@ -1266,7 +1266,7 @@ bool DriveBox_SelectDrive(HWND hwnd,LPCWSTR lpszPath) } // Don't select anything - SendMessage(hwnd,CB_SETCURSEL,(WPARAM)-1,0); + SendMessage(hwnd,CB_SETCURSEL,(WPARAM)1,0); return false; } diff --git a/src/Edit.c b/src/Edit.c index 0ea9d2f7b..60d0c71cc 100644 --- a/src/Edit.c +++ b/src/Edit.c @@ -3479,7 +3479,7 @@ void EditStripLastCharacter(HWND hwnd, bool bIgnoreSelection, bool bTrailingBlan if (bTrailingBlanksOnly) { DocPos i = iEndPos; - char ch = '\0'; + char ch; do { ch = SciCall_GetCharAt(--i); } while ((i >= iStartPos) && IsBlankChar(ch)); diff --git a/src/Encoding.c b/src/Encoding.c index 7f403b8de..bb00fb5f1 100644 --- a/src/Encoding.c +++ b/src/Encoding.c @@ -343,7 +343,7 @@ typedef struct _ee { } ENCODINGENTRY, *PENCODINGENTRY; int CmpEncoding(const void *s1, const void *s2) { - return StrCmp(((PENCODINGENTRY)s1)->wch, ((PENCODINGENTRY)s2)->wch); + return StrCmp(((const PENCODINGENTRY)s1)->wch, ((const PENCODINGENTRY)s2)->wch); } // ============================================================================ diff --git a/src/Notepad3.c b/src/Notepad3.c index bdf92934d..4e9c8f417 100644 --- a/src/Notepad3.c +++ b/src/Notepad3.c @@ -2937,7 +2937,7 @@ LRESULT MsgInitMenu(HWND hwnd, WPARAM wParam, LPARAM lParam) EnableCmd(hmenu,IDM_VIEW_CUSTOMIZETB, Settings.ShowToolbar); CheckCmd(hmenu,IDM_VIEW_STATUSBAR,Settings.ShowStatusbar); - i = SciCall_GetLexer(); + //i = SciCall_GetLexer(); //EnableCmd(hmenu,IDM_VIEW_AUTOCLOSETAGS,(i == SCLEX_HTML || i == SCLEX_XML)); CheckCmd(hmenu, IDM_VIEW_AUTOCLOSETAGS, Settings.AutoCloseTags /*&& (i == SCLEX_HTML || i == SCLEX_XML)*/); diff --git a/src/Styles.c b/src/Styles.c index 0b6bd76dc..85fc209c8 100644 --- a/src/Styles.c +++ b/src/Styles.c @@ -338,14 +338,13 @@ void Style_Load() // void Style_Save() { - WCHAR tch[32] = { L'\0' };; - WCHAR szTmpStyle[BUFSIZE_STYLE_VALUE] = { L'\0' }; size_t const len = NUMLEXERS * AVG_NUM_OF_STYLES_PER_LEXER * 100; WCHAR *pIniSection = AllocMem(len * sizeof(WCHAR), HEAP_ZERO_MEMORY); if (pIniSection) { // Custom colors for (int i = 0; i < 16; i++) { if (s_colorCustom[i] != s_colorDefault[i]) { + WCHAR tch[32] = { L'\0' }; WCHAR wch[32] = { L'\0' }; StringCchPrintf(tch, COUNTOF(tch), L"%02i", i + 1); StringCchPrintf(wch, COUNTOF(wch), L"#%02X%02X%02X", @@ -393,6 +392,7 @@ void Style_Save() while (g_pLexArray[iLexer]->Styles[i].iStyle != -1) { if (((*pLexFunction)(FCT_SETTING_CHANGE, 0) & (((__int64)1) << (i+2))) != 0LL) { // normalize + WCHAR szTmpStyle[BUFSIZE_STYLE_VALUE]; szTmpStyle[0] = L'\0'; // clear Style_CopyStyles_IfNotDefined(g_pLexArray[iLexer]->Styles[i].szValue, szTmpStyle, COUNTOF(szTmpStyle), true, true); IniSectionSetString(pIniSection, g_pLexArray[iLexer]->Styles[i].pszName, szTmpStyle); @@ -468,7 +468,6 @@ bool Style_Export(HWND hwnd) WCHAR szFile[MAX_PATH * 2] = { L'\0' }; WCHAR szFilter[256] = { L'\0' }; OPENFILENAME ofn; - DWORD dwError = ERROR_SUCCESS; ZeroMemory(&ofn,sizeof(OPENFILENAME)); GetLngString(IDS_MUI_FILTER_INI,szFilter,COUNTOF(szFilter)); @@ -485,6 +484,7 @@ bool Style_Export(HWND hwnd) if (GetSaveFileName(&ofn)) { + DWORD dwError = ERROR_SUCCESS; size_t const len = NUMLEXERS * AVG_NUM_OF_STYLES_PER_LEXER * 100; WCHAR *pIniSection = AllocMem(len * sizeof(WCHAR), HEAP_ZERO_MEMORY); if (pIniSection) { @@ -843,10 +843,10 @@ void Style_SetLexer(HWND hwnd, PEDITLEXER pLexNew) else { SendMessage(hwnd, SCI_SETCARETSTYLE, CARETSTYLE_LINE, 0); - WCHAR wch[32] = { L'\0' }; iValue = 1; fValue = 1.0f; // default caret width if (Style_StrGetSize(pCurrentStandard->Styles[STY_CARET].szValue, &fValue)) { + WCHAR wch[32] = { L'\0' }; iValue = clampi(float2int(fValue), 1, 3); // don't allow invisible 0 StringCchPrintf(wch,COUNTOF(wch),L"size:%i",iValue); StringCchCat(wchSpecificStyle,COUNTOF(wchSpecificStyle),wch); @@ -1822,10 +1822,10 @@ bool Style_StrGetFont(LPCWSTR lpszStyle, LPWSTR lpszFont, int cchFont) // bool Style_StrGetFontQuality(LPCWSTR lpszStyle,LPWSTR lpszQuality,int cchQuality) { - WCHAR tch[BUFSIZE_STYLE_VALUE] = { L'\0' }; WCHAR *p = StrStrI(lpszStyle, L"smoothing:"); if (p) { + WCHAR tch[BUFSIZE_STYLE_VALUE] = { L'\0' }; StringCchCopy(tch,COUNTOF(tch),p + CSTRLEN(L"smoothing:")); p = StrChr(tch, L';'); if (p) @@ -1929,12 +1929,10 @@ bool Style_StrGetSize(LPCWSTR lpszStyle, float* f) // bool Style_StrGetSizeStr(LPCWSTR lpszStyle,LPWSTR lpszSize,int cchSize) { - WCHAR tch[BUFSIZE_STYLE_VALUE] = { L'\0' }; - WCHAR wchFloatVal[64]; - WCHAR *p = StrStrI(lpszStyle, L"size:"); if (p) { + WCHAR tch[BUFSIZE_STYLE_VALUE] = { L'\0' }; StringCchCopy(tch, COUNTOF(tch), (p + CSTRLEN(L"size:"))); p = StrChr(tch, L';'); if (p) { *p = L'\0'; } @@ -1942,6 +1940,7 @@ bool Style_StrGetSizeStr(LPCWSTR lpszStyle,LPWSTR lpszSize,int cchSize) float fValue = 0.0f; if (Char2FloatW(tch, &fValue)) { + WCHAR wchFloatVal[64]; fValue = (float)fabs(fValue); Float2String(fValue, wchFloatVal, COUNTOF(wchFloatVal)); @@ -2034,12 +2033,12 @@ void Style_AppendWeightStr(LPWSTR lpszWeight, int cchSize, int fontWeight) // bool Style_StrGetColor(bool bFore, LPCWSTR lpszStyle, COLORREF* rgb) { - WCHAR tch[BUFSIZE_STYLE_VALUE] = { L'\0' }; WCHAR *pItem = (bFore) ? L"fore:" : L"back:"; WCHAR *p = StrStrI(lpszStyle, pItem); if (p) { + WCHAR tch[BUFSIZE_STYLE_VALUE] = { L'\0' }; StringCchCopy(tch, COUNTOF(tch), p + StringCchLenW(pItem,0)); if (tch[0] == L'#') tch[0] = L' '; @@ -2586,11 +2585,11 @@ bool Style_SelectFont(HWND hwnd,LPWSTR lpszStyle,int cchStyle, LPCWSTR sLexerNam StringCchCat(szNewStyle, COUNTOF(szNewStyle), newSize); - WCHAR chset[32] = { L'\0' }; if (bGlobalDefaultStyle && (lf.lfCharSet != DEFAULT_CHARSET) && (lf.lfCharSet != ANSI_CHARSET) && (lf.lfCharSet != Globals.iDefaultCharSet)) { + WCHAR chset[32] = { L'\0' }; if (lf.lfCharSet == iCharSet) { if (StrStrI(lpszStyle, L"charset:")) { @@ -3129,7 +3128,6 @@ INT_PTR CALLBACK Style_CustomizeSchemesDlgProc(HWND hwnd,UINT umsg,WPARAM wParam static PEDITLEXER pCurrentLexer = NULL; static PEDITSTYLE pCurrentStyle = NULL; static int iCurStyleIdx = -1; - static HFONT hFontTitle; static HBRUSH hbrFore; static HBRUSH hbrBack; static bool bIsStyleSelected = false; @@ -3137,13 +3135,11 @@ INT_PTR CALLBACK Style_CustomizeSchemesDlgProc(HWND hwnd,UINT umsg,WPARAM wParam static WCHAR* Style_StylesBackup[NUMLEXERS * AVG_NUM_OF_STYLES_PER_LEXER]; static __int64 Style_ChangedBackup[NUMLEXERS]; - WCHAR tchBuf[128] = { L'\0' }; - WCHAR wchText[512] = { L'\0' }; - switch(umsg) { case WM_INITDIALOG: { + WCHAR wchText[512] = { L'\0' }; if (Globals.hDlgIcon) { SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)Globals.hDlgIcon); } GetLngString(IDS_MUI_STYLEEDIT_HELP, wchText, COUNTOF(wchText)); SetDlgItemText(hwnd, IDC_STYLEEDIT_HELP, wchText); @@ -3207,6 +3203,7 @@ INT_PTR CALLBACK Style_CustomizeSchemesDlgProc(HWND hwnd,UINT umsg,WPARAM wParam MakeBitmapButton(hwnd,IDC_NEXTSTYLE,Globals.hInstance,IDB_NEXT); // Setup title font + static HFONT hFontTitle = NULL; if (hFontTitle) { DeleteObject(hFontTitle); } @@ -3225,6 +3222,7 @@ INT_PTR CALLBACK Style_CustomizeSchemesDlgProc(HWND hwnd,UINT umsg,WPARAM wParam else SetDlgPos(hwnd, Settings.CustomSchemesDlgPosX, Settings.CustomSchemesDlgPosY); + WCHAR tchBuf[128] = { L'\0' }; HMENU hmenu = GetSystemMenu(hwnd, false); GetLngString(IDS_MUI_PREVIEW, tchBuf, COUNTOF(tchBuf)); InsertMenu(hmenu, 0, MF_BYPOSITION | MF_STRING | MF_ENABLED, IDS_MUI_PREVIEW, tchBuf);