From f91df64fec1ad22936bc24fe388b2e32addda9ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20St=C3=B6neberg?= Date: Tue, 22 Aug 2023 12:01:30 +0200 Subject: [PATCH 1/4] fixed some Clazy `level0` warnings (#5344) Regarding the "normalized signatures" see https://github.com/KDE/clazy/blob/master/docs/checks/README-connect-not-normalized.md and https://doc.qt.io/qt-6/qmetaobject.html#normalizedSignature. --- gui/applicationlist.cpp | 2 +- gui/codeeditstyledialog.cpp | 64 ++++++++++++++++++------------------- gui/common.cpp | 2 +- gui/helpdialog.cpp | 2 +- gui/mainwindow.cpp | 22 ++++++------- gui/resultstree.cpp | 5 ++- gui/resultsview.cpp | 4 +-- gui/settingsdialog.cpp | 2 +- 8 files changed, 51 insertions(+), 52 deletions(-) diff --git a/gui/applicationlist.cpp b/gui/applicationlist.cpp index dde03718fea..80efbddbb0e 100644 --- a/gui/applicationlist.cpp +++ b/gui/applicationlist.cpp @@ -185,7 +185,7 @@ void ApplicationList::clear() bool ApplicationList::checkAndAddApplication(const QString& appPath, const QString& name, const QString& parameters) { - if (QFileInfo(appPath).exists() && QFileInfo(appPath).isExecutable()) { + if (QFileInfo::exists(appPath) && QFileInfo(appPath).isExecutable()) { Application app; app.setName(name); app.setPath("\"" + appPath + "\""); diff --git a/gui/codeeditstyledialog.cpp b/gui/codeeditstyledialog.cpp index 3b98a9282f1..fe159fc3053 100644 --- a/gui/codeeditstyledialog.cpp +++ b/gui/codeeditstyledialog.cpp @@ -172,38 +172,38 @@ StyleEditDialog::StyleEditDialog(const CodeEditorStyle& newStyle, this, SLOT(setStyleDefaultLight())); connect(mBtnDefaultDark, SIGNAL(clicked()), this, SLOT(setStyleDefaultDark())); - connect(mBtnWidgetColorFG, SIGNAL(colorChanged(const QColor&)), - this, SLOT(colorChangedWidgetFG(const QColor&))); - connect(mBtnWidgetColorBG, SIGNAL(colorChanged(const QColor&)), - this, SLOT(colorChangedWidgetBG(const QColor&))); - connect(mBtnHighlightBG, SIGNAL(colorChanged(const QColor&)), - this, SLOT(colorChangedHighlightBG(const QColor&))); - connect(mBtnLineNumFG, SIGNAL(colorChanged(const QColor&)), - this, SLOT(colorChangedLineNumFG(const QColor&))); - connect(mBtnLineNumBG, SIGNAL(colorChanged(const QColor&)), - this, SLOT(colorChangedLineNumBG(const QColor&))); - connect(mBtnKeywordFG, SIGNAL(colorChanged(const QColor&)), - this, SLOT(colorChangedKeywordFG(const QColor&))); - connect(mCBKeywordWeight, SIGNAL(weightChanged(const QFont::Weight&)), - this, SLOT(weightChangedKeyword(const QFont::Weight&))); - connect(mBtnClassFG, SIGNAL(colorChanged(const QColor&)), - this, SLOT(colorChangedClassFG(const QColor&))); - connect(mCBClassWeight, SIGNAL(weightChanged(const QFont::Weight&)), - this, SLOT(weightChangedClass(const QFont::Weight&))); - connect(mBtnQuoteFG, SIGNAL(colorChanged(const QColor&)), - this, SLOT(colorChangedQuoteFG(const QColor&))); - connect(mCBQuoteWeight, SIGNAL(weightChanged(const QFont::Weight&)), - this, SLOT(weightChangedQuote(const QFont::Weight&))); - connect(mBtnCommentFG, SIGNAL(colorChanged(const QColor&)), - this, SLOT(colorChangedCommentFG(const QColor&))); - connect(mCBCommentWeight, SIGNAL(weightChanged(const QFont::Weight&)), - this, SLOT(weightChangedComment(const QFont::Weight&))); - connect(mBtnSymbolFG, SIGNAL(colorChanged(const QColor&)), - this, SLOT(colorChangedSymbolFG(const QColor&))); - connect(mBtnSymbolBG, SIGNAL(colorChanged(const QColor&)), - this, SLOT(colorChangedSymbolBG(const QColor&))); - connect(mCBSymbolWeight, SIGNAL(weightChanged(const QFont::Weight&)), - this, SLOT(weightChangedSymbol(const QFont::Weight&))); + connect(mBtnWidgetColorFG, SIGNAL(colorChanged(QColor)), + this, SLOT(colorChangedWidgetFG(QColor))); + connect(mBtnWidgetColorBG, SIGNAL(colorChanged(QColor)), + this, SLOT(colorChangedWidgetBG(QColor))); + connect(mBtnHighlightBG, SIGNAL(colorChanged(QColor)), + this, SLOT(colorChangedHighlightBG(QColor))); + connect(mBtnLineNumFG, SIGNAL(colorChanged(QColor)), + this, SLOT(colorChangedLineNumFG(QColor))); + connect(mBtnLineNumBG, SIGNAL(colorChanged(QColor)), + this, SLOT(colorChangedLineNumBG(QColor))); + connect(mBtnKeywordFG, SIGNAL(colorChanged(QColor)), + this, SLOT(colorChangedKeywordFG(QColor))); + connect(mCBKeywordWeight, SIGNAL(weightChanged(QFont::Weight)), + this, SLOT(weightChangedKeyword(QFont::Weight))); + connect(mBtnClassFG, SIGNAL(colorChanged(QColor)), + this, SLOT(colorChangedClassFG(QColor))); + connect(mCBClassWeight, SIGNAL(weightChanged(QFont::Weight)), + this, SLOT(weightChangedClass(QFont::Weight))); + connect(mBtnQuoteFG, SIGNAL(colorChanged(QColor)), + this, SLOT(colorChangedQuoteFG(QColor))); + connect(mCBQuoteWeight, SIGNAL(weightChanged(QFont::Weight)), + this, SLOT(weightChangedQuote(QFont::Weight))); + connect(mBtnCommentFG, SIGNAL(colorChanged(QColor)), + this, SLOT(colorChangedCommentFG(QColor))); + connect(mCBCommentWeight, SIGNAL(weightChanged(QFont::Weight)), + this, SLOT(weightChangedComment(QFont::Weight))); + connect(mBtnSymbolFG, SIGNAL(colorChanged(QColor)), + this, SLOT(colorChangedSymbolFG(QColor))); + connect(mBtnSymbolBG, SIGNAL(colorChanged(QColor)), + this, SLOT(colorChangedSymbolBG(QColor))); + connect(mCBSymbolWeight, SIGNAL(weightChanged(QFont::Weight)), + this, SLOT(weightChangedSymbol(QFont::Weight))); } void StyleEditDialog::updateControls() diff --git a/gui/common.cpp b/gui/common.cpp index 68b20217831..a1547538d0a 100644 --- a/gui/common.cpp +++ b/gui/common.cpp @@ -79,7 +79,7 @@ QString getDataDir() if (!dataDir.isEmpty()) return dataDir; const QString appPath = QFileInfo(QCoreApplication::applicationFilePath()).canonicalPath(); - if (QFileInfo(appPath + "/std.cfg").exists()) + if (QFileInfo::exists(appPath + "/std.cfg")) return appPath; if (appPath.indexOf("/cppcheck/", 0, Qt::CaseInsensitive) > 0) return appPath.left(appPath.indexOf("/cppcheck/", 0, Qt::CaseInsensitive) + 9); diff --git a/gui/helpdialog.cpp b/gui/helpdialog.cpp index 80f7d900ffc..bb9e5d5f692 100644 --- a/gui/helpdialog.cpp +++ b/gui/helpdialog.cpp @@ -66,7 +66,7 @@ static QString getHelpFile() #endif for (const QString &p: paths) { QString filename = p + "/online-help.qhc"; - if (QFileInfo(filename).exists()) + if (QFileInfo::exists(filename)) return filename; } return QString(); diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index fd5dc6dfff0..aa377098b7a 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -137,7 +137,7 @@ MainWindow::MainWindow(TranslationHandler* th, QSettings* settings) : mLineEditFilter->setPlaceholderText(tr("Quick Filter:")); mLineEditFilter->setClearButtonEnabled(true); mUI->mToolBarFilter->addWidget(mLineEditFilter); - connect(mLineEditFilter, SIGNAL(textChanged(const QString&)), mFilterTimer, SLOT(start())); + connect(mLineEditFilter, SIGNAL(textChanged(QString)), mFilterTimer, SLOT(start())); connect(mLineEditFilter, &QLineEdit::returnPressed, this, &MainWindow::filterResults); connect(mUI->mActionPrint, SIGNAL(triggered()), mUI->mResults, SLOT(print())); @@ -610,14 +610,14 @@ void MainWindow::analyzeCode(const QString& code, const QString& filename) // Initialize dummy ThreadResult as ErrorLogger ThreadResult result; result.setFiles(QStringList(filename)); - connect(&result, SIGNAL(progress(int,const QString&)), - mUI->mResults, SLOT(progress(int,const QString&))); - connect(&result, SIGNAL(error(const ErrorItem&)), - mUI->mResults, SLOT(error(const ErrorItem&))); - connect(&result, SIGNAL(log(const QString&)), - mUI->mResults, SLOT(log(const QString&))); - connect(&result, SIGNAL(debugError(const ErrorItem&)), - mUI->mResults, SLOT(debugError(const ErrorItem&))); + connect(&result, SIGNAL(progress(int,QString)), + mUI->mResults, SLOT(progress(int,QString))); + connect(&result, SIGNAL(error(ErrorItem)), + mUI->mResults, SLOT(error(ErrorItem))); + connect(&result, SIGNAL(log(QString)), + mUI->mResults, SLOT(log(QString))); + connect(&result, SIGNAL(debugError(ErrorItem)), + mUI->mResults, SLOT(debugError(ErrorItem))); // Create CppCheck instance CppCheck cppcheck(result, true, nullptr); @@ -1649,7 +1649,7 @@ bool MainWindow::loadLastResults() const QString &lastResults = getLastResults(); if (lastResults.isEmpty()) return false; - if (!QFileInfo(lastResults).exists()) + if (!QFileInfo::exists(lastResults)) return false; mUI->mResults->readErrorsXml(lastResults); mUI->mResults->setCheckDirectory(mSettings->value(SETTINGS_LAST_CHECK_PATH,QString()).toString()); @@ -1916,7 +1916,7 @@ void MainWindow::updateMRUMenuItems() // Do a sanity check - remove duplicates and non-existing projects int removed = projects.removeDuplicates(); for (int i = projects.size() - 1; i >= 0; i--) { - if (!QFileInfo(projects[i]).exists()) { + if (!QFileInfo::exists(projects[i])) { projects.removeAt(i); removed++; } diff --git a/gui/resultstree.cpp b/gui/resultstree.cpp index 946437f9602..3870fd64cf0 100644 --- a/gui/resultstree.cpp +++ b/gui/resultstree.cpp @@ -861,7 +861,7 @@ QString ResultsTree::askFileDir(const QString &file) return QString(); // User selected root path - if (QFileInfo(dir + '/' + file).exists()) + if (QFileInfo::exists(dir + '/' + file)) mCheckPath = dir; // user selected checked folder @@ -870,7 +870,7 @@ QString ResultsTree::askFileDir(const QString &file) QString folderName = file.mid(0, file.indexOf('/')); if (dir.indexOf('/' + folderName + '/')) dir = dir.mid(0, dir.lastIndexOf('/' + folderName + '/')); - if (QFileInfo(dir + '/' + file).exists()) + if (QFileInfo::exists(dir + '/' + file)) mCheckPath = dir; } @@ -1018,7 +1018,6 @@ void ResultsTree::suppressSelectedIds() if (!mSelectionModel) return; - QModelIndexList selectedRows = mSelectionModel->selectedRows(); QSet selectedIds; for (QModelIndex index : mSelectionModel->selectedRows()) { QStandardItem *item = mModel.itemFromIndex(index); diff --git a/gui/resultsview.cpp b/gui/resultsview.cpp index 6c57e8c159a..b26d22be484 100644 --- a/gui/resultsview.cpp +++ b/gui/resultsview.cpp @@ -383,7 +383,7 @@ void ResultsView::readErrorsXml(const QString &filename) QString dir; if (!errors.isEmpty() && !errors[0].errorPath.isEmpty()) { QString relativePath = QFileInfo(filename).canonicalPath(); - if (QFileInfo(relativePath + '/' + errors[0].errorPath[0].file).exists()) + if (QFileInfo::exists(relativePath + '/' + errors[0].errorPath[0].file)) dir = relativePath; } @@ -432,7 +432,7 @@ void ResultsView::updateDetails(const QModelIndex &index) const int lineNumber = data["line"].toInt(); QString filepath = data["file"].toString(); - if (!QFileInfo(filepath).exists() && QFileInfo(mUI->mTree->getCheckDirectory() + '/' + filepath).exists()) + if (!QFileInfo::exists(filepath) && QFileInfo::exists(mUI->mTree->getCheckDirectory() + '/' + filepath)) filepath = mUI->mTree->getCheckDirectory() + '/' + filepath; QStringList symbols; diff --git a/gui/settingsdialog.cpp b/gui/settingsdialog.cpp index 1e8d13a4474..72569b9f962 100644 --- a/gui/settingsdialog.cpp +++ b/gui/settingsdialog.cpp @@ -92,7 +92,7 @@ SettingsDialog::SettingsDialog(ApplicationList *list, mCurrentStyle = new CodeEditorStyle(CodeEditorStyle::loadSettings(&settings)); manageStyleControls(); - connect(mUI->mEditPythonPath, SIGNAL(textEdited(const QString&)), + connect(mUI->mEditPythonPath, SIGNAL(textEdited(QString)), this, SLOT(validateEditPythonPath())); connect(mUI->mButtons, &QDialogButtonBox::accepted, this, &SettingsDialog::ok); From 5bb4c6f5bcb6c6b564fbe59be656e868e9430b2f Mon Sep 17 00:00:00 2001 From: andymacg <117683405+andymacg@users.noreply.github.com> Date: Tue, 22 Aug 2023 06:03:12 -0400 Subject: [PATCH 2/4] Fix #11878 FP misra-c2012-18.7 on function pointer parameter with array-type args (#5343) https://trac.cppcheck.net/ticket/11878#ticket --- addons/misra.py | 5 ++++- addons/test/misra/misra-test.c | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/addons/misra.py b/addons/misra.py index eaea81dfb9d..7201c27591c 100755 --- a/addons/misra.py +++ b/addons/misra.py @@ -3231,7 +3231,10 @@ def misra_18_7(self, data): if token.str == '{': token = token.link - if cppcheckdata.simpleMatch(token, "[ ]"): + # skip function pointer parameter types + if token.astOperand1 is None: + pass + elif cppcheckdata.simpleMatch(token, "[ ]"): self.reportError(token, 18, 7) break token = token.next diff --git a/addons/test/misra/misra-test.c b/addons/test/misra/misra-test.c index d4e7f39ad6c..b1a0baca2b0 100644 --- a/addons/test/misra/misra-test.c +++ b/addons/test/misra/misra-test.c @@ -1713,6 +1713,7 @@ struct { } r18_7_struct; // 8.4 struct { uint16_t len; + int (*array_param_func_ptr)(char const *argv[], int argc); // no-warning uint8_t data_1[ 19 ]; uint8_t data_2[ ]; // 18.7 } r18_7_struct; // 8.4 From 5a136c3f38969a71c19a90816fc83ec6125a0618 Mon Sep 17 00:00:00 2001 From: andymacg <117683405+andymacg@users.noreply.github.com> Date: Tue, 22 Aug 2023 06:18:12 -0400 Subject: [PATCH 3/4] Fix #11877 FP misra 10.4 On array member comparison (#5342) I also changed the comment header to run tests on misra-test-avr8.c because I thought that was the intention to use it like misra-test.c; if not, I can revert. --- addons/misra.py | 10 ++++++++-- addons/test/misra/misra-test-avr8.c | 16 +++++++++++++++- addons/test/misra/misra-test.c | 8 ++++++++ 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/addons/misra.py b/addons/misra.py index 7201c27591c..9c22efe218f 100755 --- a/addons/misra.py +++ b/addons/misra.py @@ -466,9 +466,15 @@ def getEssentialTypeCategory(expr): return expr.valueType.sign if expr.valueType and expr.valueType.typeScope and expr.valueType.typeScope.className: return "enum<" + expr.valueType.typeScope.className + ">" + # Unwrap membership, dereferences and array indexing vartok = expr - while simpleMatch(vartok, '[') or (vartok and vartok.str == '*' and vartok.astOperand2 is None): - vartok = vartok.astOperand1 + while True: + if simpleMatch(vartok, '[') or (vartok and vartok.str == '*' and vartok.astOperand2 is None): + vartok = vartok.astOperand1 + elif simpleMatch(vartok, '.'): + vartok = vartok.astOperand2 + else: + break if vartok and vartok.variable: typeToken = vartok.variable.typeStartToken while typeToken and typeToken.isName: diff --git a/addons/test/misra/misra-test-avr8.c b/addons/test/misra/misra-test-avr8.c index e5ba751d496..a552ac09c66 100644 --- a/addons/test/misra/misra-test-avr8.c +++ b/addons/test/misra/misra-test-avr8.c @@ -1,5 +1,5 @@ // To test: -// ~/cppcheck/cppcheck --addon=misra --platform=avr8 misra-test-avr8.c +// ~/cppcheck/cppcheck--dump -DDUMMY --suppress=uninitvar --inline-suppr misra/misra-test-avr8.c --std=c89 --platform=avr8 && python3 ../misra.py -verify misra/misra-test-avr8.c.dump static void misra_10_4(void) { @@ -7,6 +7,20 @@ static void misra_10_4(void) const char buf[1] = {'f'}; const char c = '0'; x = buf[0] - c; + + const char buf[2] = {0}; + x = 'a' == buf[0]; // no-warning + + typedef struct { + int t; + char buf[2]; + } foo_t; + const foo_t cmd = {0}; + x = 'b' == cmd.buf[0]; // no-warning + + const foo_t * pcmd = &cmd; + x='c' == pcmd->buf[0]; // no-warning + (void)cmd.t; } static void misra_12_2(void) { diff --git a/addons/test/misra/misra-test.c b/addons/test/misra/misra-test.c index b1a0baca2b0..29fadd938d6 100644 --- a/addons/test/misra/misra-test.c +++ b/addons/test/misra/misra-test.c @@ -709,6 +709,14 @@ static void misra_10_4(u32 x, s32 y) { if ('0' == buf[x]) // no-warning { } + + const struct foo_s{ + int t; + char buf[2]; + } cmd = {0}; + if ('\0' == cmd.buf[0]) //no-warning + { + } } static void misra_10_5(uint16_t x) { From 18b526b08a98a6cab77cd7a56c2775bcd2da451f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Tue, 22 Aug 2023 14:49:08 +0200 Subject: [PATCH 4/4] CI: Fix selfcheck cppcheck warnings (#5359) --- addons/test/misra/misra-test-avr8.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/addons/test/misra/misra-test-avr8.c b/addons/test/misra/misra-test-avr8.c index a552ac09c66..faa6eb6b615 100644 --- a/addons/test/misra/misra-test-avr8.c +++ b/addons/test/misra/misra-test-avr8.c @@ -1,15 +1,15 @@ // To test: -// ~/cppcheck/cppcheck--dump -DDUMMY --suppress=uninitvar --inline-suppr misra/misra-test-avr8.c --std=c89 --platform=avr8 && python3 ../misra.py -verify misra/misra-test-avr8.c.dump +// ~/cppcheck/cppcheck--dump -DDUMMY --suppress=uninitvar misra/misra-test-avr8.c --std=c89 --platform=avr8 && python3 ../misra.py -verify misra/misra-test-avr8.c.dump static void misra_10_4(void) { // #10480 - const char buf[1] = {'f'}; + const char buf1[1] = {a}; const char c = '0'; - x = buf[0] - c; + x = buf1[0] - c; - const char buf[2] = {0}; - x = 'a' == buf[0]; // no-warning + const char buf2[2] = {x,y}; + x = 'a' == buf2[0]; // no-warning typedef struct { int t;