Code enhancement: Fix GCC warnings

- fix conversion warnings
- fix missing-field-initializers warnings
- fix unused-parameter warnings
- fix deprecated-copy warnings
- add initializers

Fix #13122, close #13123
This commit is contained in:
ozone10 2023-02-11 19:24:07 +01:00 committed by Don Ho
parent e163c6d0aa
commit 4a4f96cefc
12 changed files with 52 additions and 40 deletions

View File

@ -125,9 +125,10 @@ bool AllowDarkModeForWindow(HWND hWnd, bool allow)
bool IsHighContrast() bool IsHighContrast()
{ {
HIGHCONTRASTW highContrast = { sizeof(highContrast) }; HIGHCONTRASTW highContrast{};
if (SystemParametersInfoW(SPI_GETHIGHCONTRAST, sizeof(highContrast), &highContrast, FALSE)) highContrast.cbSize = sizeof(HIGHCONTRASTW);
return highContrast.dwFlags & HCF_HIGHCONTRASTON; if (SystemParametersInfoW(SPI_GETHIGHCONTRAST, sizeof(HIGHCONTRASTW), &highContrast, FALSE))
return (highContrast.dwFlags & HCF_HIGHCONTRASTON) == HCF_HIGHCONTRASTON;
return false; return false;
} }

View File

@ -785,7 +785,7 @@ bool str2numberVector(generic_string str2convert, std::vector<size_t>& numVect)
} }
std::vector<generic_string> v = stringSplit(str2convert, TEXT(" ")); std::vector<generic_string> v = stringSplit(str2convert, TEXT(" "));
for (auto i : v) for (const auto& i : v)
{ {
// Don't treat empty string and the number greater than 9999 // Don't treat empty string and the number greater than 9999
if (!i.empty() && i.length() < 5) if (!i.empty() && i.length() < 5)
@ -827,7 +827,7 @@ generic_string stringTakeWhileAdmissable(const generic_string& input, const gene
} }
double stodLocale(const generic_string& str, _locale_t loc, size_t* idx) double stodLocale(const generic_string& str, [[maybe_unused]] _locale_t loc, size_t* idx)
{ {
// Copied from the std::stod implementation but uses _wcstod_l instead of wcstod. // Copied from the std::stod implementation but uses _wcstod_l instead of wcstod.
const wchar_t* ptr = str.c_str(); const wchar_t* ptr = str.c_str();
@ -1690,7 +1690,7 @@ void Version::setVersionFrom(const generic_string& filePath)
return; return;
unsigned char* buffer = new unsigned char[bufferSize]; unsigned char* buffer = new unsigned char[bufferSize];
::GetFileVersionInfo(filePath.c_str(), uselessArg, bufferSize, buffer); ::GetFileVersionInfo(filePath.c_str(), 0, bufferSize, buffer);
VS_FIXEDFILEINFO* lpFileInfo = nullptr; VS_FIXEDFILEINFO* lpFileInfo = nullptr;
UINT cbFileInfo = 0; UINT cbFileInfo = 0;

View File

@ -1803,8 +1803,9 @@ bool NppParameters::isInFontList(const generic_string& fontName2Search) const
HFONT NppParameters::getDefaultUIFont() HFONT NppParameters::getDefaultUIFont()
{ {
static HFONT g_defaultMessageFont = []() { static HFONT g_defaultMessageFont = []() {
NONCLIENTMETRICS ncm = { sizeof(ncm) }; NONCLIENTMETRICS ncm{};
SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(ncm), &ncm, 0); ncm.cbSize = sizeof(NONCLIENTMETRICS);
SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS), &ncm, 0);
return CreateFontIndirect(&ncm.lfMessageFont); return CreateFontIndirect(&ncm.lfMessageFont);
}(); }();
@ -3280,7 +3281,7 @@ void NppParameters::writeDefaultUDL()
{ {
bool firstCleanDone = false; bool firstCleanDone = false;
std::vector<bool> deleteState; std::vector<bool> deleteState;
for (auto udl : _pXmlUserLangsDoc) for (const auto& udl : _pXmlUserLangsDoc)
{ {
if (!_pXmlUserLangDoc) if (!_pXmlUserLangDoc)
{ {
@ -3337,7 +3338,7 @@ void NppParameters::writeDefaultUDL()
void NppParameters::writeNonDefaultUDL() void NppParameters::writeNonDefaultUDL()
{ {
for (auto udl : _pXmlUserLangsDoc) for (auto& udl : _pXmlUserLangsDoc)
{ {
if (udl._isDirty && udl._udlXmlDoc != nullptr && udl._udlXmlDoc != _pXmlUserLangDoc) if (udl._isDirty && udl._udlXmlDoc != nullptr && udl._udlXmlDoc != _pXmlUserLangDoc)
{ {

View File

@ -1256,7 +1256,8 @@ intptr_t CALLBACK FindReplaceDlg::run_dlgProc(UINT message, WPARAM wParam, LPARA
HWND hDirCombo = ::GetDlgItem(_hSelf, IDD_FINDINFILES_DIR_COMBO); HWND hDirCombo = ::GetDlgItem(_hSelf, IDD_FINDINFILES_DIR_COMBO);
// Change handler of edit element in the comboboxes to support Ctrl+Backspace // Change handler of edit element in the comboboxes to support Ctrl+Backspace
COMBOBOXINFO cbinfo = { sizeof(COMBOBOXINFO) }; COMBOBOXINFO cbinfo{};
cbinfo.cbSize = sizeof(COMBOBOXINFO);
GetComboBoxInfo(hFindCombo, &cbinfo); GetComboBoxInfo(hFindCombo, &cbinfo);
if (!cbinfo.hwndItem) return FALSE; if (!cbinfo.hwndItem) return FALSE;
@ -1689,7 +1690,7 @@ intptr_t CALLBACK FindReplaceDlg::run_dlgProc(UINT message, WPARAM wParam, LPARA
{ {
setStatusbarMessage(TEXT(""), FSNoMessage); setStatusbarMessage(TEXT(""), FSNoMessage);
const int filterSize = 512; const int filterSize = 512;
TCHAR filters[filterSize + 1]; TCHAR filters[filterSize + 1] = { '\0' };
filters[filterSize] = '\0'; filters[filterSize] = '\0';
TCHAR directory[MAX_PATH]; TCHAR directory[MAX_PATH];
::GetDlgItemText(_hSelf, IDD_FINDINFILES_FILTERS_COMBO, filters, filterSize); ::GetDlgItemText(_hSelf, IDD_FINDINFILES_FILTERS_COMBO, filters, filterSize);
@ -5494,8 +5495,8 @@ int Progress::createProgressWindow()
int height = cPBheight + cBTNheight + textHeight + progressBarPadding + morePadding; int height = cPBheight + cBTNheight + textHeight + progressBarPadding + morePadding;
POINT center; POINT center{};
RECT callerRect; RECT callerRect{};
::GetWindowRect(_hCallerWnd, &callerRect); ::GetWindowRect(_hCallerWnd, &callerRect);
center.x = (callerRect.left + callerRect.right) / 2; center.x = (callerRect.left + callerRect.right) / 2;
center.y = (callerRect.top + callerRect.bottom) / 2; center.y = (callerRect.top + callerRect.bottom) / 2;

View File

@ -1017,15 +1017,15 @@ intptr_t CALLBACK UserDefineDialog::run_dlgProc(UINT message, WPARAM wParam, LPA
_ctrlTab.createTabs(_wVector); _ctrlTab.createTabs(_wVector);
_ctrlTab.display(); _ctrlTab.display();
RECT arc; RECT arc{};
::GetWindowRect(::GetDlgItem(_hSelf, IDC_IMPORT_BUTTON), &arc); ::GetWindowRect(::GetDlgItem(_hSelf, IDC_IMPORT_BUTTON), &arc);
POINT p; POINT p{};
p.x = arc.left; p.x = arc.left;
p.y = arc.bottom; p.y = arc.bottom;
::ScreenToClient(_hSelf, &p); ::ScreenToClient(_hSelf, &p);
RECT rc; RECT rc{};
getClientRect(rc); getClientRect(rc);
rc.top = p.y + 10; rc.top = p.y + 10;
rc.bottom -= 20; rc.bottom -= 20;
@ -1051,14 +1051,14 @@ intptr_t CALLBACK UserDefineDialog::run_dlgProc(UINT message, WPARAM wParam, LPA
if (!(BST_CHECKED == ::SendDlgItemMessage(_hSelf, IDC_UD_PERCENTAGE_SLIDER, BM_GETCHECK, 0, 0))) if (!(BST_CHECKED == ::SendDlgItemMessage(_hSelf, IDC_UD_PERCENTAGE_SLIDER, BM_GETCHECK, 0, 0)))
::EnableWindow(::GetDlgItem(_hSelf, IDC_UD_PERCENTAGE_SLIDER), FALSE); ::EnableWindow(::GetDlgItem(_hSelf, IDC_UD_PERCENTAGE_SLIDER), FALSE);
} }
SCROLLINFO si; SCROLLINFO si{};
si.cbSize = sizeof(si); si.cbSize = sizeof(si);
si.fMask = SIF_RANGE; //| SIF_PAGE; si.fMask = SIF_RANGE; //| SIF_PAGE;
si.nMin = 0; si.nMin = 0;
si.nMax = 0; si.nMax = 0;
::SetScrollInfo(_hSelf, SB_VERT, &si, TRUE); ::SetScrollInfo(_hSelf, SB_VERT, &si, TRUE);
TCHAR temp[32]; TCHAR temp[32] = { '\0' };
generic_string udlVersion = TEXT("User Defined Language v."); generic_string udlVersion = TEXT("User Defined Language v.");
udlVersion += _itow(SCE_UDL_VERSION_MAJOR, temp, 10); udlVersion += _itow(SCE_UDL_VERSION_MAJOR, temp, 10);
udlVersion += TEXT("."); udlVersion += TEXT(".");
@ -1221,7 +1221,7 @@ intptr_t CALLBACK UserDefineDialog::run_dlgProc(UINT message, WPARAM wParam, LPA
{ {
auto i = ::SendDlgItemMessage(_hSelf, IDC_LANGNAME_COMBO, CB_GETCURSEL, 0, 0); auto i = ::SendDlgItemMessage(_hSelf, IDC_LANGNAME_COMBO, CB_GETCURSEL, 0, 0);
const size_t langNameLen = 256; const size_t langNameLen = 256;
TCHAR langName[langNameLen + 1]; TCHAR langName[langNameLen + 1] = { '\0' };
auto cbTextLen = ::SendDlgItemMessage(_hSelf, IDC_LANGNAME_COMBO, CB_GETLBTEXTLEN, i, 0); auto cbTextLen = ::SendDlgItemMessage(_hSelf, IDC_LANGNAME_COMBO, CB_GETLBTEXTLEN, i, 0);
if (static_cast<size_t>(cbTextLen) > langNameLen) if (static_cast<size_t>(cbTextLen) > langNameLen)
return TRUE; return TRUE;
@ -1250,7 +1250,7 @@ intptr_t CALLBACK UserDefineDialog::run_dlgProc(UINT message, WPARAM wParam, LPA
{ {
auto i = ::SendDlgItemMessage(_hSelf, IDC_LANGNAME_COMBO, CB_GETCURSEL, 0, 0); auto i = ::SendDlgItemMessage(_hSelf, IDC_LANGNAME_COMBO, CB_GETCURSEL, 0, 0);
const size_t langNameLen = 256; const size_t langNameLen = 256;
TCHAR langName[langNameLen + 1]; TCHAR langName[langNameLen + 1] = { '\0' };
auto cbTextLen = ::SendDlgItemMessage(_hSelf, IDC_LANGNAME_COMBO, CB_GETLBTEXTLEN, i, 0); auto cbTextLen = ::SendDlgItemMessage(_hSelf, IDC_LANGNAME_COMBO, CB_GETLBTEXTLEN, i, 0);
if (static_cast<size_t>(cbTextLen) > langNameLen) if (static_cast<size_t>(cbTextLen) > langNameLen)
return TRUE; return TRUE;
@ -1454,7 +1454,7 @@ intptr_t CALLBACK UserDefineDialog::run_dlgProc(UINT message, WPARAM wParam, LPA
int maxPos = originalHight - _currentHight; int maxPos = originalHight - _currentHight;
// Set the vertical scrolling range and page size // Set the vertical scrolling range and page size
SCROLLINFO si; SCROLLINFO si{};
si.cbSize = sizeof(si); si.cbSize = sizeof(si);
si.fMask = SIF_RANGE | SIF_PAGE; si.fMask = SIF_RANGE | SIF_PAGE;
si.nMin = 0; si.nMin = 0;
@ -1618,8 +1618,7 @@ intptr_t CALLBACK StringDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM)
{ {
case IDOK : case IDOK :
{ {
TCHAR tmpName[langNameLenMax]; TCHAR tmpName[langNameLenMax] = { '\0' };
tmpName[0] = '\0';
::GetDlgItemText(_hSelf, IDC_STRING_EDIT, tmpName, langNameLenMax); ::GetDlgItemText(_hSelf, IDC_STRING_EDIT, tmpName, langNameLenMax);
_textValue = tmpName; _textValue = tmpName;
::EndDialog(_hSelf, reinterpret_cast<intptr_t>(_textValue.c_str())); ::EndDialog(_hSelf, reinterpret_cast<intptr_t>(_textValue.c_str()));
@ -1684,7 +1683,7 @@ LRESULT StringDlg::customEditProc(HWND hEdit, UINT msg, WPARAM wParam, LPARAM lP
return CallWindowProc(pSelf->_oldEditProc, hEdit, msg, wParam, lParam); return CallWindowProc(pSelf->_oldEditProc, hEdit, msg, wParam, lParam);
} }
bool StringDlg::isAllowed(const generic_string & txt) bool StringDlg::isAllowed([[maybe_unused]] const generic_string & txt)
{ {
#ifndef __MINGW32__ #ifndef __MINGW32__
for (auto ch : txt) for (auto ch : txt)

View File

@ -376,7 +376,7 @@ LRESULT DockingCont::runProcCaption(HWND hwnd, UINT Message, WPARAM wParam, LPAR
if ((_bCaptionTT == TRUE) || (_hoverMPos == posClose)) if ((_bCaptionTT == TRUE) || (_hoverMPos == posClose))
{ {
TRACKMOUSEEVENT tme; TRACKMOUSEEVENT tme{};
tme.cbSize = sizeof(tme); tme.cbSize = sizeof(tme);
tme.hwndTrack = hwnd; tme.hwndTrack = hwnd;
tme.dwFlags = TME_LEAVE | TME_HOVER; tme.dwFlags = TME_LEAVE | TME_HOVER;
@ -717,7 +717,15 @@ LRESULT DockingCont::runProcTab(HWND hwnd, UINT Message, WPARAM wParam, LPARAM l
int nSelTab = TabCtrl_GetCurSel(hwnd); int nSelTab = TabCtrl_GetCurSel(hwnd);
for (int i = 0; i < nTabs; ++i) for (int i = 0; i < nTabs; ++i)
{ {
DRAWITEMSTRUCT dis = { ODT_TAB, id, (UINT)i, ODA_DRAWENTIRE, ODS_DEFAULT, hwnd, hdc }; DRAWITEMSTRUCT dis{};
dis.CtlType = ODT_TAB;
dis.CtlID = id;
dis.itemID = static_cast<UINT>(i);
dis.itemAction = ODA_DRAWENTIRE;
dis.itemState = ODS_DEFAULT;
dis.hwndItem = hwnd;
dis.hDC = hdc;
TabCtrl_GetItemRect(hwnd, i, &dis.rcItem); TabCtrl_GetItemRect(hwnd, i, &dis.rcItem);
if (i == nFocusTab) if (i == nFocusTab)
@ -857,7 +865,7 @@ LRESULT DockingCont::runProcTab(HWND hwnd, UINT Message, WPARAM wParam, LPARAM l
if ((_bTabTTHover == FALSE) && (iItem != iItemSel)) if ((_bTabTTHover == FALSE) && (iItem != iItemSel))
{ {
TRACKMOUSEEVENT tme; TRACKMOUSEEVENT tme{};
tme.cbSize = sizeof(tme); tme.cbSize = sizeof(tme);
tme.hwndTrack = hwnd; tme.hwndTrack = hwnd;
tme.dwFlags = TME_LEAVE | TME_HOVER; tme.dwFlags = TME_LEAVE | TME_HOVER;
@ -1324,7 +1332,7 @@ void DockingCont::onSize()
SWP_NOZORDER); SWP_NOZORDER);
// Notify switch in // Notify switch in
NMHDR nmhdr; NMHDR nmhdr{};
nmhdr.code = DMN_FLOATDROPPED; nmhdr.code = DMN_FLOATDROPPED;
nmhdr.hwndFrom = _hSelf; nmhdr.hwndFrom = _hSelf;
nmhdr.idFrom = 0; nmhdr.idFrom = 0;
@ -1543,7 +1551,7 @@ void DockingCont::selectTab(int iTab)
::SetFocus(((tTbData*)tcItem.lParam)->hClient); ::SetFocus(((tTbData*)tcItem.lParam)->hClient);
// Notify switch in // Notify switch in
NMHDR nmhdr; NMHDR nmhdr{};
nmhdr.code = DMN_SWITCHIN; nmhdr.code = DMN_SWITCHIN;
nmhdr.hwndFrom = _hSelf; nmhdr.hwndFrom = _hSelf;
nmhdr.idFrom = 0; nmhdr.idFrom = 0;
@ -1559,7 +1567,7 @@ void DockingCont::selectTab(int iTab)
::ShowWindow(((tTbData*)tcItem.lParam)->hClient, SW_HIDE); ::ShowWindow(((tTbData*)tcItem.lParam)->hClient, SW_HIDE);
// Notify switch off // Notify switch off
NMHDR nmhdr; NMHDR nmhdr{};
nmhdr.code = DMN_SWITCHOFF; nmhdr.code = DMN_SWITCHOFF;
nmhdr.hwndFrom = _hSelf; nmhdr.hwndFrom = _hSelf;
nmhdr.idFrom = 0; nmhdr.idFrom = 0;

View File

@ -564,7 +564,7 @@ size_t FunctionZoneParser::getBodyClosePos(size_t begin, const TCHAR *bodyOpenSy
return targetEnd; return targetEnd;
} }
void FunctionZoneParser::classParse(vector<foundInfo> & foundInfos, vector< pair<size_t, size_t> > &scannedZones, const std::vector< std::pair<size_t, size_t> > & commentZones, size_t begin, size_t end, ScintillaEditView **ppEditView, generic_string classStructName) void FunctionZoneParser::classParse(vector<foundInfo> & foundInfos, vector< pair<size_t, size_t> > &scannedZones, const std::vector< std::pair<size_t, size_t> > & commentZones, size_t begin, size_t end, ScintillaEditView **ppEditView, generic_string /*classStructName*/)
{ {
if (begin >= end) if (begin >= end)
return; return;
@ -582,7 +582,7 @@ void FunctionZoneParser::classParse(vector<foundInfo> & foundInfos, vector< pair
// Get class name // Get class name
intptr_t foundPos = 0; intptr_t foundPos = 0;
generic_string classStructName = parseSubLevel(targetStart, targetEnd, _classNameExprArray, foundPos, ppEditView); generic_string subLevelClassStructName = parseSubLevel(targetStart, targetEnd, _classNameExprArray, foundPos, ppEditView);
if (!_openSymbole.empty() && !_closeSymbole.empty()) if (!_openSymbole.empty() && !_closeSymbole.empty())
@ -603,7 +603,7 @@ void FunctionZoneParser::classParse(vector<foundInfo> & foundInfos, vector< pair
//vector< generic_string > emptyArray; //vector< generic_string > emptyArray;
if (!isInZones(targetStart, commentZones)) if (!isInZones(targetStart, commentZones))
{ {
funcParse(foundInfos, targetStart, targetEnd, ppEditView, classStructName, &commentZones); funcParse(foundInfos, targetStart, targetEnd, ppEditView, subLevelClassStructName, &commentZones);
} }
begin = targetStart + (targetEnd - targetStart); begin = targetStart + (targetEnd - targetStart);
targetStart = (*ppEditView)->searchInTarget(_rangeExpr.c_str(), _rangeExpr.length(), begin, end); targetStart = (*ppEditView)->searchInTarget(_rangeExpr.c_str(), _rangeExpr.length(), begin, end);

View File

@ -57,7 +57,7 @@ float CharDistributionAnalysis::GetConfidence(void)
if (mTotalChars != mFreqChars) if (mTotalChars != mFreqChars)
{ {
float r = mFreqChars / ((mTotalChars - mFreqChars) * mTypicalDistributionRatio); float r = static_cast<float>(mFreqChars) / (static_cast<float>(mTotalChars - mFreqChars) * mTypicalDistributionRatio);
if (r < SURE_YES) if (r < SURE_YES)
return r; return r;

View File

@ -186,7 +186,7 @@ float JapaneseContextAnalysis::GetConfidence(void)
{ {
//This is just one way to calculate confidence. It works well for me. //This is just one way to calculate confidence. It works well for me.
if (mTotalRel > mDataThreshold) if (mTotalRel > mDataThreshold)
return ((float)(mTotalRel - mRelSample[0]))/mTotalRel; return static_cast<float>(mTotalRel - mRelSample[0]) / static_cast<float>(mTotalRel);
else else
return (float)DONT_KNOW; return (float)DONT_KNOW;
} }

View File

@ -158,8 +158,9 @@ float nsLatin1Prober::GetConfidence(void)
confidence = 0.0f; confidence = 0.0f;
else else
{ {
confidence = mFreqCounter[3]*1.0f / total; const float floatTotal = static_cast<float>(total);
confidence -= mFreqCounter[1]*20.0f/total; confidence = static_cast<float>(mFreqCounter[3]) / floatTotal;
confidence -= static_cast<float>(mFreqCounter[1]) * 20.0f / floatTotal;
} }
if (confidence < 0.0f) if (confidence < 0.0f)

View File

@ -72,6 +72,7 @@ struct nsPkgInt {
nsPkgInt(nsIdxSft a,nsSftMsk b, nsBitSft c,nsUnitMsk d,const PRUint32* const e) nsPkgInt(nsIdxSft a,nsSftMsk b, nsBitSft c,nsUnitMsk d,const PRUint32* const e)
:idxsft(a), sftmsk(b), bitsft(c), unitmsk(d), data(e){} :idxsft(a), sftmsk(b), bitsft(c), unitmsk(d), data(e){}
nsPkgInt(); nsPkgInt();
nsPkgInt(const nsPkgInt&) = default;
nsPkgInt operator= (const nsPkgInt&); nsPkgInt operator= (const nsPkgInt&);
}; };

View File

@ -102,8 +102,8 @@ float nsSingleByteCharSetProber::GetConfidence(void)
float r; float r;
if (mTotalSeqs > 0) { if (mTotalSeqs > 0) {
r = ((float)1.0) * mSeqCounters[POSITIVE_CAT] / mTotalSeqs / mModel->mTypicalPositiveRatio; r = static_cast<float>(mSeqCounters[POSITIVE_CAT]) / static_cast<float>(mTotalSeqs) / mModel->mTypicalPositiveRatio;
r = r*mFreqChar/mTotalChar; r = r * static_cast<float>(mFreqChar) / static_cast<float>(mTotalChar);
if (r >= (float)1.00) if (r >= (float)1.00)
r = (float)0.99; r = (float)0.99;
return r; return r;