Skip to content

Commit 3fbe2e2

Browse files
committed
fixed #13659 - set proper line for file-level unmatchedSuppression
1 parent 8840415 commit 3fbe2e2

File tree

3 files changed

+16
-18
lines changed

3 files changed

+16
-18
lines changed

cli/cppcheckexecutor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ static std::vector<::ErrorMessage> reportUnmatchedSuppressions(const std::list<S
328328

329329
std::list<::ErrorMessage::FileLocation> callStack;
330330
if (!s.fileName.empty()) {
331-
callStack.emplace_back(s.fileName, s.lineNumber, 0);
331+
callStack.emplace_back(s.fileName, s.lineNumber == -1 ? 0 : s.lineNumber, 0); // TODO: get rid of s.lineNumber == -1 hack
332332
}
333333
const std::string unmatchedSuppressionId = s.isPolyspace ? "unmatchedPolyspaceSuppression" : "unmatchedSuppression";
334334
auto errmsg = ::ErrorMessage(std::move(callStack), "", Severity::information, "Unmatched suppression: " + s.errorId, unmatchedSuppressionId, Certainty::normal);

test/cli/other_test.py

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3367,11 +3367,10 @@ def test_suppress_unmatched_wildcard(tmp_path): # #13660
33673367
exitcode, stdout, stderr = cppcheck(args, cwd=tmp_path)
33683368
assert exitcode == 0, stdout
33693369
assert stdout.splitlines() == []
3370-
# TODO: invalid locations - see #13659
33713370
assert stderr.splitlines() == [
3372-
'test*.c:-1:0: information: Unmatched suppression: id [unmatchedSuppression]',
3373-
'test*.c:-1:0: information: Unmatched suppression: id2 [unmatchedSuppression]',
3374-
'tes?.c:-1:0: information: Unmatched suppression: id2 [unmatchedSuppression]'
3371+
'test*.c:0:0: information: Unmatched suppression: id [unmatchedSuppression]',
3372+
'test*.c:0:0: information: Unmatched suppression: id2 [unmatchedSuppression]',
3373+
'tes?.c:0:0: information: Unmatched suppression: id2 [unmatchedSuppression]'
33753374
]
33763375

33773376

@@ -3396,12 +3395,11 @@ def test_suppress_unmatched_wildcard_unchecked(tmp_path):
33963395
exitcode, stdout, stderr = cppcheck(args, cwd=tmp_path)
33973396
assert exitcode == 0, stdout
33983397
assert stdout.splitlines() == []
3399-
# TODO: invalid locations - see #13659
34003398
assert stderr.splitlines() == [
3401-
'test*.c:-1:0: information: Unmatched suppression: id [unmatchedSuppression]',
3402-
'tes?.c:-1:0: information: Unmatched suppression: id [unmatchedSuppression]',
3403-
'*:-1:0: information: Unmatched suppression: id2 [unmatchedSuppression]',
3404-
'test*.c:-1:0: information: Unmatched suppression: * [unmatchedSuppression]'
3399+
'test*.c:0:0: information: Unmatched suppression: id [unmatchedSuppression]',
3400+
'tes?.c:0:0: information: Unmatched suppression: id [unmatchedSuppression]',
3401+
'*:0:0: information: Unmatched suppression: id2 [unmatchedSuppression]',
3402+
'test*.c:0:0: information: Unmatched suppression: * [unmatchedSuppression]'
34053403
]
34063404

34073405

@@ -3855,12 +3853,12 @@ def test_unmatched_file(tmp_path): # #14248 / #14249
38553853
ret, stdout, stderr = cppcheck(args)
38563854
assert stdout == ''
38573855
assert stderr.splitlines() == [
3858-
f'{lib_file}:-1:0: information: Unmatched suppression: error [unmatchedSuppression]',
3859-
f'{lib_file}:-1:0: information: Unmatched suppression: error2 [unmatchedSuppression]',
3860-
f'{lib_file}:-1:0: information: Unmatched suppression: error3 [unmatchedSuppression]',
3861-
f'{lib_file}:-1:0: information: Unmatched suppression: error4 [unmatchedSuppression]',
3862-
f'{lib_file}:-1:0: information: Unmatched suppression: error5 [unmatchedSuppression]',
3863-
f'{lib_file}:-1:0: information: Unmatched suppression: error6 [unmatchedSuppression]'
3856+
f'{lib_file}:0:0: information: Unmatched suppression: error [unmatchedSuppression]',
3857+
f'{lib_file}:0:0: information: Unmatched suppression: error2 [unmatchedSuppression]',
3858+
f'{lib_file}:0:0: information: Unmatched suppression: error3 [unmatchedSuppression]',
3859+
f'{lib_file}:0:0: information: Unmatched suppression: error4 [unmatchedSuppression]',
3860+
f'{lib_file}:0:0: information: Unmatched suppression: error5 [unmatchedSuppression]',
3861+
f'{lib_file}:0:0: information: Unmatched suppression: error6 [unmatchedSuppression]'
38643862
]
38653863
assert ret == 0, stdout
38663864

test/testsuppressions.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@ class TestSuppressions : public TestFixture {
542542
" b++;\n"
543543
"}\n",
544544
"uninitvar:test.cpp"));
545-
ASSERT_EQUALS("[test.cpp]: (information) Unmatched suppression: uninitvar [unmatchedSuppression]\n", errout_str());
545+
ASSERT_EQUALS("[test.cpp:0:0]: (information) Unmatched suppression: uninitvar [unmatchedSuppression]\n", errout_str());
546546

547547
// suppress all for this file only
548548
ASSERT_EQUALS(0, (this->*check)("void f() {\n"
@@ -558,7 +558,7 @@ class TestSuppressions : public TestFixture {
558558
" b++;\n"
559559
"}\n",
560560
"*:test.cpp"));
561-
ASSERT_EQUALS("[test.cpp]: (information) Unmatched suppression: * [unmatchedSuppression]\n", errout_str());
561+
ASSERT_EQUALS("[test.cpp:0:0]: (information) Unmatched suppression: * [unmatchedSuppression]\n", errout_str());
562562

563563
// suppress uninitvar for this file and line
564564
ASSERT_EQUALS(0, (this->*check)("void f() {\n"

0 commit comments

Comments
 (0)