Skip to content

Commit bbdf547

Browse files
authored
fixed #13810 - fixed missing column for unmatchedSuppression (#8276)
1 parent 517adae commit bbdf547

7 files changed

Lines changed: 31 additions & 26 deletions

cli/cppcheckexecutor.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ static std::vector<ErrorMessage> getUnmatchedSuppressions(const std::list<Suppre
309309
// check if this unmatched suppression is suppressed
310310
bool suppressed = false;
311311
for (const SuppressionList::Suppression &s2 : unmatched) {
312-
if (s2.errorId == "unmatchedSuppression") {
312+
if (s2.errorId == "unmatchedSuppression") { // TODO: handle unmatchedPolyspaceSuppression?
313313
if ((s2.fileName.empty() || s2.fileName == "*" || s2.fileName == s.fileName) &&
314314
(s2.lineNumber == SuppressionList::Suppression::NO_LINE || s2.lineNumber == s.lineNumber)) {
315315
suppressed = true;
@@ -329,7 +329,7 @@ static std::vector<ErrorMessage> getUnmatchedSuppressions(const std::list<Suppre
329329

330330
std::list<ErrorMessage::FileLocation> callStack;
331331
if (!s.fileName.empty()) {
332-
callStack.emplace_back(s.fileName, s.lineNumber == -1 ? 0 : s.lineNumber, 0); // TODO: set column - see #13810 / get rid of s.lineNumber == -1 hack
332+
callStack.emplace_back(s.fileName, s.lineNumber == -1 ? 0 : s.lineNumber, s.column); // TODO: get rid of s.lineNumber == -1 hack
333333
}
334334
const std::string unmatchedSuppressionId = s.isPolyspace ? "unmatchedPolyspaceSuppression" : "unmatchedSuppression";
335335
errors.emplace_back(std::move(callStack), "", Severity::information, "Unmatched suppression: " + s.errorId, unmatchedSuppressionId, Certainty::normal);
@@ -345,6 +345,7 @@ bool CppCheckExecutor::reportUnmatchedSuppressions(const Settings &settings, con
345345
// bail out if there is a suppression of unmatchedSuppression which matches any file
346346
auto suppr = suppressions.getSuppressions();
347347
if (std::any_of(suppr.cbegin(), suppr.cend(), [](const SuppressionList::Suppression& s) {
348+
// TODO: handle unmatchedPolyspaceSuppression?
348349
return s.errorId == "unmatchedSuppression" && (s.fileName.empty() || s.fileName == "*") && s.lineNumber == SuppressionList::Suppression::NO_LINE;
349350
}))
350351
return false;

cli/processexecutor.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ namespace {
113113
{
114114
std::string suppr_str = suppr.toString();
115115
suppr_str += ";";
116+
suppr_str += std::to_string(suppr.column);
117+
suppr_str += ";";
116118
suppr_str += suppr.checked ? "1" : "0";
117119
suppr_str += ";";
118120
suppr_str += suppr.matched ? "1" : "0";
@@ -241,18 +243,19 @@ bool ProcessExecutor::handleRead(int rpipe, unsigned int &result, const std::str
241243
if (!buf.empty()) {
242244
// TODO: avoid string splitting
243245
auto parts = splitString(buf, ';');
244-
if (parts.size() < 4)
246+
if (parts.size() < 5)
245247
{
246248
// TODO: make this non-fatal
247249
std::cerr << "#### ThreadExecutor::handleRead(" << filename << ") adding of inline suppression failed - insufficient data" << std::endl;
248250
std::exit(EXIT_FAILURE);
249251
}
250252
auto suppr = SuppressionList::parseLine(parts[0]);
251253
suppr.isInline = (type == PipeWriter::REPORT_SUPPR_INLINE);
252-
suppr.checked = parts[1] == "1";
253-
suppr.matched = parts[2] == "1";
254-
suppr.extraComment = parts[3];
255-
for (std::size_t i = 4; i < parts.size(); i++) {
254+
suppr.column = strToInt<int>(parts[1]);
255+
suppr.checked = parts[2] == "1";
256+
suppr.matched = parts[3] == "1";
257+
suppr.extraComment = parts[4];
258+
for (std::size_t i = 5; i < parts.size(); i++) {
256259
suppr.extraComment += ";" + parts[i];
257260
}
258261
const std::string err = mSuppressions.nomsg.addSuppression(suppr);

lib/suppressions.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,7 @@ bool SuppressionList::isSuppressed(const SuppressionList::ErrorMessage &errmsg,
473473
{
474474
std::lock_guard<std::mutex> lg(mSuppressionsSync);
475475

476+
// TODO: handle unmatchedPolyspaceSuppression?
476477
const bool unmatchedSuppression(errmsg.errorId == "unmatchedSuppression");
477478
bool returnValue = false;
478479
for (Suppression &s : mSuppressions) {

test/cli/inline-suppress-polyspace_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def test_unmatched_polyspace_suppression(tmp_path):
1515
args = ['--addon=misra', '--template=simple', '--enable=style,information', '--inline-suppr', 'test.c']
1616

1717
out_exp = ['Checking test.c ...']
18-
err_exp = ['test.c:1:0: information: Unmatched suppression: misra-c2012-8.2 [unmatchedPolyspaceSuppression]']
18+
err_exp = ['test.c:1:14: information: Unmatched suppression: misra-c2012-8.2 [unmatchedPolyspaceSuppression]']
1919

2020
assert_cppcheck(args, ec_exp=0, err_exp=err_exp, out_exp=out_exp, cwd=str(tmp_path))
2121

test/cli/inline-suppress_test.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def test_unmatched_suppression():
8282
ret, stdout, stderr = cppcheck(args, cwd=__script_dir)
8383
lines = stderr.splitlines()
8484
assert lines == [
85-
'{}2.c:2:0: information: Unmatched suppression: some_warning_id [unmatchedSuppression]'.format(__proj_inline_suppres_path)
85+
'{}2.c:2:1: information: Unmatched suppression: some_warning_id [unmatchedSuppression]'.format(__proj_inline_suppres_path)
8686
]
8787
assert stdout == ''
8888
assert ret == 1, stdout
@@ -100,7 +100,7 @@ def test_unmatched_suppression_path_with_extra_stuff():
100100
ret, stdout, stderr = cppcheck(args, cwd=__script_dir)
101101
lines = stderr.splitlines()
102102
assert lines == [
103-
'{}2.c:2:0: information: Unmatched suppression: some_warning_id [unmatchedSuppression]'.format(__proj_inline_suppres_path)
103+
'{}2.c:2:1: information: Unmatched suppression: some_warning_id [unmatchedSuppression]'.format(__proj_inline_suppres_path)
104104
]
105105
assert stdout == ''
106106
assert ret == 1, stdout
@@ -431,8 +431,8 @@ def __test_unused_function_unmatched(tmpdir, extra_args):
431431
lines = stderr.splitlines()
432432
lines.sort()
433433
assert lines == [
434-
'{}unusedFunctionUnmatched.cpp:5:0: information: Unmatched suppression: uninitvar [unmatchedSuppression]'.format(__proj_inline_suppres_path),
435-
'{}unusedFunctionUnmatched.cpp:5:0: information: Unmatched suppression: unusedFunction [unmatchedSuppression]'.format(__proj_inline_suppres_path)
434+
'{}unusedFunctionUnmatched.cpp:5:1: information: Unmatched suppression: uninitvar [unmatchedSuppression]'.format(__proj_inline_suppres_path),
435+
'{}unusedFunctionUnmatched.cpp:5:1: information: Unmatched suppression: unusedFunction [unmatchedSuppression]'.format(__proj_inline_suppres_path)
436436
]
437437
assert stdout == ''
438438
assert ret == 0, stdout
@@ -478,7 +478,7 @@ def test_unused_function_disabled_unmatched():
478478

479479
ret, stdout, stderr = cppcheck(args, cwd=__script_dir)
480480
assert stderr.splitlines() == [
481-
'{}unusedFunctionUnmatched.cpp:5:0: information: Unmatched suppression: uninitvar [unmatchedSuppression]'.format(__proj_inline_suppres_path)
481+
'{}unusedFunctionUnmatched.cpp:5:1: information: Unmatched suppression: uninitvar [unmatchedSuppression]'.format(__proj_inline_suppres_path)
482482
]
483483
assert stdout == ''
484484
assert ret == 0, stdout
@@ -496,8 +496,8 @@ def test_unmatched_cfg():
496496

497497
ret, stdout, stderr = cppcheck(args, cwd=__script_dir)
498498
assert stderr.splitlines() == [
499-
'{}cfg.c:5:0: information: Unmatched suppression: id [unmatchedSuppression]'.format(__proj_inline_suppres_path),
500-
'{}cfg.c:9:0: information: Unmatched suppression: id [unmatchedSuppression]'.format(__proj_inline_suppres_path),
499+
'{}cfg.c:5:5: information: Unmatched suppression: id [unmatchedSuppression]'.format(__proj_inline_suppres_path),
500+
'{}cfg.c:9:5: information: Unmatched suppression: id [unmatchedSuppression]'.format(__proj_inline_suppres_path),
501501
]
502502
assert stdout == ''
503503
assert ret == 0, stdout
@@ -518,7 +518,7 @@ def test_unused_function_disabled_unmatched_j():
518518

519519
ret, stdout, stderr = cppcheck(args, cwd=__script_dir)
520520
assert stderr.splitlines() == [
521-
'{}unusedFunctionUnmatched.cpp:5:0: information: Unmatched suppression: uninitvar [unmatchedSuppression]'.format(__proj_inline_suppres_path)
521+
'{}unusedFunctionUnmatched.cpp:5:1: information: Unmatched suppression: uninitvar [unmatchedSuppression]'.format(__proj_inline_suppres_path)
522522
]
523523
assert stdout == ''
524524
assert ret == 0, stdout
@@ -536,7 +536,7 @@ def test_misra_disabled_unmatched(): #14232
536536

537537
ret, stdout, stderr = cppcheck(args, cwd=__script_dir)
538538
assert stderr.splitlines() == [
539-
'{}misraUnmatched.c:5:0: information: Unmatched suppression: uninitvar [unmatchedSuppression]'.format(__proj_inline_suppres_path)
539+
'{}misraUnmatched.c:5:1: information: Unmatched suppression: uninitvar [unmatchedSuppression]'.format(__proj_inline_suppres_path)
540540
]
541541
assert stdout == ''
542542
assert ret == 0, stdout
@@ -554,7 +554,7 @@ def test_premium_disabled_unmatched(): #13663
554554

555555
ret, stdout, stderr = cppcheck(args, cwd=__script_dir)
556556
assert stderr.splitlines() == [
557-
'{}premiumUnmatched.cpp:5:0: information: Unmatched suppression: uninitvar [unmatchedSuppression]'.format(__proj_inline_suppres_path)
557+
'{}premiumUnmatched.cpp:5:1: information: Unmatched suppression: uninitvar [unmatchedSuppression]'.format(__proj_inline_suppres_path)
558558
]
559559
assert stdout == ''
560560
assert ret == 0, stdout

test/cli/other_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2449,7 +2449,7 @@ def __test_inline_suppr(tmp_path, extra_args): # #13087
24492449
assert exitcode == 0, stdout
24502450
assert stdout == ''
24512451
assert stderr.splitlines() == [
2452-
'{}:4:0: information: Unmatched suppression: memleak [unmatchedSuppression]'.format(test_file)
2452+
'{}:4:1: information: Unmatched suppression: memleak [unmatchedSuppression]'.format(test_file)
24532453
]
24542454

24552455

test/testsuppressions.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ class TestSuppressions : public TestFixture {
578578
" b++;\n"
579579
"}\n",
580580
""));
581-
ASSERT_EQUALS("[test.cpp:1:0]: (information) Unmatched suppression: uninitvar [unmatchedSuppression]\n", errout_str());
581+
ASSERT_EQUALS("[test.cpp:1:1]: (information) Unmatched suppression: uninitvar [unmatchedSuppression]\n", errout_str());
582582

583583
// suppress uninitvar for this file only
584584
ASSERT_EQUALS(0, (this->*check)("void f() {\n"
@@ -756,7 +756,7 @@ class TestSuppressions : public TestFixture {
756756
" b++;\n"
757757
"}\n",
758758
""));
759-
ASSERT_EQUALS("[test.cpp:4:0]: (information) Unmatched suppression: uninitvar [unmatchedSuppression]\n", errout_str());
759+
ASSERT_EQUALS("[test.cpp:4:5]: (information) Unmatched suppression: uninitvar [unmatchedSuppression]\n", errout_str());
760760

761761
// suppress block inline checks
762762
ASSERT_EQUALS(0, (this->*check)("void f() {\n"
@@ -939,7 +939,7 @@ class TestSuppressions : public TestFixture {
939939
" // cppcheck-suppress-end [uninitvar, syntaxError]\n"
940940
"}\n",
941941
""));
942-
ASSERT_EQUALS("[test.cpp:2:0]: (information) Unmatched suppression: syntaxError [unmatchedSuppression]\n", errout_str());
942+
ASSERT_EQUALS("[test.cpp:2:5]: (information) Unmatched suppression: syntaxError [unmatchedSuppression]\n", errout_str());
943943

944944
ASSERT_EQUALS(1, (this->*check)("// cppcheck-suppress-begin [uninitvar, syntaxError]\n"
945945
"void f() {\n"
@@ -954,7 +954,7 @@ class TestSuppressions : public TestFixture {
954954
"}\n"
955955
"// cppcheck-suppress-end [uninitvar, syntaxError]\n",
956956
""));
957-
ASSERT_EQUALS("[test.cpp:1:0]: (information) Unmatched suppression: syntaxError [unmatchedSuppression]\n", errout_str());
957+
ASSERT_EQUALS("[test.cpp:1:1]: (information) Unmatched suppression: syntaxError [unmatchedSuppression]\n", errout_str());
958958

959959
ASSERT_EQUALS(1, (this->*check)("// cppcheck-suppress-begin [uninitvar, syntaxError]\n"
960960
"void f() {\n"
@@ -969,7 +969,7 @@ class TestSuppressions : public TestFixture {
969969
"}\n"
970970
"// cppcheck-suppress-end [uninitvar, syntaxError]",
971971
""));
972-
ASSERT_EQUALS("[test.cpp:1:0]: (information) Unmatched suppression: syntaxError [unmatchedSuppression]\n", errout_str());
972+
ASSERT_EQUALS("[test.cpp:1:1]: (information) Unmatched suppression: syntaxError [unmatchedSuppression]\n", errout_str());
973973

974974
// test of multiple suppression types
975975
ASSERT_EQUALS(0, (this->*check)("// cppcheck-suppress-file uninitvar\n"
@@ -1019,7 +1019,7 @@ class TestSuppressions : public TestFixture {
10191019
" a++;\n"
10201020
"}\n",
10211021
""));
1022-
ASSERT_EQUALS("[test.cpp:4:0]: (information) Unmatched suppression: uninitvar [unmatchedSuppression]\n", errout_str());
1022+
ASSERT_EQUALS("[test.cpp:4:5]: (information) Unmatched suppression: uninitvar [unmatchedSuppression]\n", errout_str());
10231023

10241024
// #5746 - exitcode
10251025
ASSERT_EQUALS(1U,
@@ -1048,7 +1048,7 @@ class TestSuppressions : public TestFixture {
10481048
"#define DIV(A,B) A/B\n"
10491049
"a = DIV(10,1);\n",
10501050
"");
1051-
ASSERT_EQUALS("[test.cpp:2:0]: (information) Unmatched suppression: abc [unmatchedSuppression]\n", errout_str());
1051+
ASSERT_EQUALS("[test.cpp:2:1]: (information) Unmatched suppression: abc [unmatchedSuppression]\n", errout_str());
10521052
}
10531053

10541054
void suppressionsSettingsFiles() {

0 commit comments

Comments
 (0)