Skip to content

Commit

Permalink
Merge branch 'danmar:main' into chr_macrostring
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github committed Aug 22, 2023
2 parents 272fb64 + 18b526b commit cf92b4b
Show file tree
Hide file tree
Showing 11 changed files with 89 additions and 58 deletions.
15 changes: 12 additions & 3 deletions addons/misra.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -3231,7 +3237,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
Expand Down
20 changes: 17 additions & 3 deletions addons/test/misra/misra-test-avr8.c
Original file line number Diff line number Diff line change
@@ -1,12 +1,26 @@
// To test:
// ~/cppcheck/cppcheck --addon=misra --platform=avr8 misra-test-avr8.c
// ~/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 buf2[2] = {x,y};
x = 'a' == buf2[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) {
Expand Down
9 changes: 9 additions & 0 deletions addons/test/misra/misra-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -1713,6 +1721,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
Expand Down
2 changes: 1 addition & 1 deletion gui/applicationlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 + "\"");
Expand Down
64 changes: 32 additions & 32 deletions gui/codeeditstyledialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion gui/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion gui/helpdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
22 changes: 11 additions & 11 deletions gui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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++;
}
Expand Down
5 changes: 2 additions & 3 deletions gui/resultstree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}

Expand Down Expand Up @@ -1018,7 +1018,6 @@ void ResultsTree::suppressSelectedIds()
if (!mSelectionModel)
return;

QModelIndexList selectedRows = mSelectionModel->selectedRows();
QSet<QString> selectedIds;
for (QModelIndex index : mSelectionModel->selectedRows()) {
QStandardItem *item = mModel.itemFromIndex(index);
Expand Down
4 changes: 2 additions & 2 deletions gui/resultsview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion gui/settingsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit cf92b4b

Please sign in to comment.