Skip to content

Commit a090614

Browse files
committed
Suppressions: New extensible Suppressions xml format that allow more attributes. To start with it also allows symbolName.
1 parent 148af12 commit a090614

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1062
-566
lines changed

.travis_suppressions

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ knownConditionTrueFalse:build/*
1010
nullPointer:lib/checkother.cpp
1111
nullPointer:build/checkother.cpp
1212

13-
*:gui/test*
13+
*:gui/test/*
1414
*:test/test.cxx
15-
*:test/cfg*
15+
*:test/cfg/*
1616

17-
*:externals*
18-
*:htmlreport*
19-
*:samples*
17+
*:externals/*/*
18+
*:htmlreport/*
19+
*:samples/*/bad.c*

cli/cmdlineparser.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,15 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
228228
}
229229
}
230230

231+
else if (std::strncmp(argv[i], "--suppress-xml=", 15) == 0) {
232+
const char * filename = argv[i] + 15;
233+
const std::string errmsg(_settings->nomsg.parseXmlFile(filename));
234+
if (!errmsg.empty()) {
235+
PrintMessage(errmsg);
236+
return false;
237+
}
238+
}
239+
231240
else if (std::strncmp(argv[i], "--suppress=", 11) == 0) {
232241
const std::string suppression = argv[i]+11;
233242
const std::string errmsg(_settings->nomsg.addSuppressionLine(suppression));

cli/threadexecutor.cpp

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -117,14 +117,7 @@ int ThreadExecutor::handleRead(int rpipe, unsigned int &result)
117117
ErrorLogger::ErrorMessage msg;
118118
msg.deserialize(buf);
119119

120-
std::string file;
121-
unsigned int line(0);
122-
if (!msg._callStack.empty()) {
123-
file = msg._callStack.back().getfile(false);
124-
line = msg._callStack.back().line;
125-
}
126-
127-
if (!_settings.nomsg.isSuppressed(msg._id, file, line)) {
120+
if (!_settings.nomsg.isSuppressed(msg.toSuppressionsErrorMessage())) {
128121
// Alert only about unique errors
129122
std::string errmsg = msg.toString(_settings.verbose);
130123
if (std::find(_errorList.begin(), _errorList.end(), errmsg) == _errorList.end()) {
@@ -309,7 +302,7 @@ unsigned int ThreadExecutor::check()
309302
"cppcheckError",
310303
false);
311304

312-
if (!_settings.nomsg.isSuppressed(errmsg._id, childname, 0))
305+
if (!_settings.nomsg.isSuppressed(errmsg.toSuppressionsErrorMessage()))
313306
_errorLogger.reportErr(errmsg);
314307
}
315308
}
@@ -502,14 +495,7 @@ void ThreadExecutor::reportInfo(const ErrorLogger::ErrorMessage &msg)
502495

503496
void ThreadExecutor::report(const ErrorLogger::ErrorMessage &msg, MessageType msgType)
504497
{
505-
std::string file;
506-
unsigned int line(0);
507-
if (!msg._callStack.empty()) {
508-
file = msg._callStack.back().getfile(false);
509-
line = msg._callStack.back().line;
510-
}
511-
512-
if (_settings.nomsg.isSuppressed(msg._id, file, line))
498+
if (_settings.nomsg.isSuppressed(msg.toSuppressionsErrorMessage()))
513499
return;
514500

515501
// Alert only about unique errors

gui/checkthread.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,20 @@ void CheckThread::parseClangErrors(const QString &tool, const QString &file0, QS
419419
foreach (const ErrorItem &e, errorItems) {
420420
if (e.errorPath.isEmpty())
421421
continue;
422-
if (mSuppressions.contains(e.errorId))
422+
Suppressions::ErrorMessage errorMessage;
423+
errorMessage.setFileName(e.errorPath.back().file.toStdString());
424+
errorMessage.lineNumber = e.errorPath.back().line;
425+
errorMessage.errorId = e.errorId.toStdString();
426+
errorMessage.symbolNames = e.symbolNames.toStdString();
427+
428+
bool isSuppressed = false;
429+
foreach (const Suppressions::Suppression &suppression, mSuppressions) {
430+
if (suppression.isSuppressed(errorMessage)) {
431+
isSuppressed = true;
432+
break;
433+
}
434+
}
435+
if (isSuppressed)
423436
continue;
424437
std::list<ErrorLogger::ErrorMessage::FileLocation> callstack;
425438
foreach (const QErrorPathItem &path, e.errorPath) {

gui/checkthread.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <QThread>
2424
#include "cppcheck.h"
2525
#include "threadresult.h"
26+
#include "suppressions.h"
2627

2728
class Settings;
2829

@@ -68,7 +69,7 @@ class CheckThread : public QThread {
6869
mClangIncludePaths = s;
6970
}
7071

71-
void setSuppressions(const QStringList s) {
72+
void setSuppressions(const QList<Suppressions::Suppression> &s) {
7273
mSuppressions = s;
7374
}
7475

@@ -151,7 +152,7 @@ class CheckThread : public QThread {
151152
QStringList mAddonsAndTools;
152153
QString mDataDir;
153154
QStringList mClangIncludePaths;
154-
QStringList mSuppressions;
155+
QList<Suppressions::Suppression> mSuppressions;
155156
QString mMisraFile;
156157
};
157158
/// @}

gui/erroritem.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ ErrorItem::ErrorItem(const ErrorLogger::ErrorMessage &errmsg)
4646
, summary(QString::fromStdString(errmsg.shortMessage()))
4747
, message(QString::fromStdString(errmsg.verboseMessage()))
4848
, cwe(errmsg._cwe.id)
49+
, symbolNames(QString::fromStdString(errmsg.symbolNames()))
4950
{
5051
for (std::list<ErrorLogger::ErrorMessage::FileLocation>::const_iterator loc = errmsg._callStack.begin();
5152
loc != errmsg._callStack.end();

gui/erroritem.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ class ErrorItem {
8989
QString message;
9090
int cwe;
9191
QList<QErrorPathItem> errorPath;
92+
QString symbolNames;
9293

9394
// Special GUI properties
9495
QString sinceDate;

gui/gui.pro

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ FORMS = about.ui \
5959
stats.ui \
6060
librarydialog.ui \
6161
libraryaddfunctiondialog.ui \
62-
libraryeditargdialog.ui
62+
libraryeditargdialog.ui \
63+
newsuppressiondialog.ui
6364

6465
TRANSLATIONS = cppcheck_de.ts \
6566
cppcheck_es.ts \
@@ -113,10 +114,11 @@ HEADERS += aboutdialog.h \
113114
txtreport.h \
114115
xmlreport.h \
115116
xmlreportv2.h \
116-
librarydialog.h \
117-
cppchecklibrarydata.h \
118-
libraryaddfunctiondialog.h \
119-
libraryeditargdialog.h
117+
librarydialog.h \
118+
cppchecklibrarydata.h \
119+
libraryaddfunctiondialog.h \
120+
libraryeditargdialog.h \
121+
newsuppressiondialog.h
120122

121123
SOURCES += aboutdialog.cpp \
122124
application.cpp \
@@ -149,10 +151,11 @@ SOURCES += aboutdialog.cpp \
149151
txtreport.cpp \
150152
xmlreport.cpp \
151153
xmlreportv2.cpp \
152-
librarydialog.cpp \
153-
cppchecklibrarydata.cpp \
154-
libraryaddfunctiondialog.cpp \
155-
libraryeditargdialog.cpp
154+
librarydialog.cpp \
155+
cppchecklibrarydata.cpp \
156+
libraryaddfunctiondialog.cpp \
157+
libraryeditargdialog.cpp \
158+
newsuppressiondialog.cpp
156159

157160
win32 {
158161
RC_FILE = cppcheck-gui.rc

gui/mainwindow.cpp

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -832,9 +832,9 @@ Settings MainWindow::getCppcheckSettings()
832832
tryLoadLibrary(&result.library, filename);
833833
}
834834

835-
const QStringList suppressions = mProjectFile->getSuppressions();
836-
foreach (QString suppression, suppressions) {
837-
result.nomsg.addSuppressionLine(suppression.toStdString());
835+
const QList<Suppressions::Suppression> &suppressions = mProjectFile->getSuppressions();
836+
foreach (const Suppressions::Suppression &suppression, suppressions) {
837+
result.nomsg.addSuppression(suppression);
838838
}
839839

840840
// Only check the given -D configuration
@@ -1729,13 +1729,26 @@ void MainWindow::tagged()
17291729

17301730
void MainWindow::suppressIds(QStringList ids)
17311731
{
1732-
if (mProjectFile) {
1733-
QStringList suppressions = mProjectFile->getSuppressions();
1734-
foreach (QString s, ids) {
1735-
if (!suppressions.contains(s))
1736-
suppressions << s;
1732+
if (!mProjectFile)
1733+
return;
1734+
ids.removeDuplicates();
1735+
1736+
QList<Suppressions::Suppression> suppressions = mProjectFile->getSuppressions();
1737+
foreach (QString id, ids) {
1738+
// Remove all matching suppressions
1739+
std::string id2 = id.toStdString();
1740+
for (int i = 0; i < suppressions.size();) {
1741+
if (suppressions[i].errorId == id2)
1742+
suppressions.removeAt(i);
1743+
else
1744+
++i;
17371745
}
1738-
mProjectFile->setSuppressions(suppressions);
1739-
mProjectFile->write();
1746+
1747+
Suppressions::Suppression newSuppression;
1748+
newSuppression.errorId = id2;
1749+
suppressions << newSuppression;
17401750
}
1751+
1752+
mProjectFile->setSuppressions(suppressions);
1753+
mProjectFile->write();
17411754
}

gui/newsuppressiondialog.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#include "newsuppressiondialog.h"
2+
#include "ui_newsuppressiondialog.h"
3+
4+
NewSuppressionDialog::NewSuppressionDialog(QWidget *parent) :
5+
QDialog(parent),
6+
mUI(new Ui::NewSuppressionDialog)
7+
{
8+
mUI->setupUi(this);
9+
}
10+
11+
NewSuppressionDialog::~NewSuppressionDialog()
12+
{
13+
delete mUI;
14+
}
15+
16+
void NewSuppressionDialog::setErrorIds(const QStringList &errorIds)
17+
{
18+
mUI->mComboErrorId->addItems(errorIds);
19+
mUI->mComboErrorId->setCurrentIndex(-1);
20+
mUI->mComboErrorId->setCurrentText("");
21+
}
22+
23+
Suppressions::Suppression NewSuppressionDialog::getSuppression() const
24+
{
25+
Suppressions::Suppression ret;
26+
ret.errorId = mUI->mComboErrorId->currentText().toStdString();
27+
ret.fileName = mUI->mTextFileName->text().toStdString();
28+
ret.lineNumber = mUI->mTextLineNumber->text().toInt();
29+
ret.symbolName = mUI->mTextSymbolName->text().toStdString();
30+
return ret;
31+
}

0 commit comments

Comments
 (0)