Skip to content

Commit 2414a90

Browse files
committed
fixed #13659 - set proper line for file-level unmatchedSuppression
1 parent 64abf20 commit 2414a90

3 files changed

Lines changed: 16 additions & 18 deletions

File tree

cli/cppcheckexecutor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ static bool reportUnmatchedSuppressions(const std::list<SuppressionList::Suppres
327327

328328
std::list<::ErrorMessage::FileLocation> callStack;
329329
if (!s.fileName.empty()) {
330-
callStack.emplace_back(s.fileName, s.lineNumber, 0);
330+
callStack.emplace_back(s.fileName, s.lineNumber == -1 ? 0 : s.lineNumber, 0); // TODO: get rid of s.lineNumber == -1 hack
331331
}
332332
const std::string unmatchedSuppressionId = s.isPolyspace ? "unmatchedPolyspaceSuppression" : "unmatchedSuppression";
333333
errorLogger.reportErr(::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
@@ -3371,11 +3371,10 @@ def test_suppress_unmatched_wildcard(tmp_path): # #13660
33713371
exitcode, stdout, stderr = cppcheck(args, cwd=tmp_path)
33723372
assert exitcode == 0, stdout
33733373
assert stdout.splitlines() == []
3374-
# TODO: invalid locations - see #13659
33753374
assert stderr.splitlines() == [
3376-
'test*.c:-1:0: information: Unmatched suppression: id [unmatchedSuppression]',
3377-
'test*.c:-1:0: information: Unmatched suppression: id2 [unmatchedSuppression]',
3378-
'tes?.c:-1:0: information: Unmatched suppression: id2 [unmatchedSuppression]'
3375+
'test*.c:0:0: information: Unmatched suppression: id [unmatchedSuppression]',
3376+
'test*.c:0:0: information: Unmatched suppression: id2 [unmatchedSuppression]',
3377+
'tes?.c:0:0: information: Unmatched suppression: id2 [unmatchedSuppression]'
33793378
]
33803379

33813380

@@ -3400,12 +3399,11 @@ def test_suppress_unmatched_wildcard_unchecked(tmp_path):
34003399
exitcode, stdout, stderr = cppcheck(args, cwd=tmp_path)
34013400
assert exitcode == 0, stdout
34023401
assert stdout.splitlines() == []
3403-
# TODO: invalid locations - see #13659
34043402
assert stderr.splitlines() == [
3405-
'test*.c:-1:0: information: Unmatched suppression: id [unmatchedSuppression]',
3406-
'tes?.c:-1:0: information: Unmatched suppression: id [unmatchedSuppression]',
3407-
'*:-1:0: information: Unmatched suppression: id2 [unmatchedSuppression]',
3408-
'test*.c:-1:0: information: Unmatched suppression: * [unmatchedSuppression]'
3403+
'test*.c:0:0: information: Unmatched suppression: id [unmatchedSuppression]',
3404+
'tes?.c:0:0: information: Unmatched suppression: id [unmatchedSuppression]',
3405+
'*:0:0: information: Unmatched suppression: id2 [unmatchedSuppression]',
3406+
'test*.c:0:0: information: Unmatched suppression: * [unmatchedSuppression]'
34093407
]
34103408

34113409

@@ -3859,12 +3857,12 @@ def test_unmatched_file(tmp_path): # #14248 / #14249
38593857
ret, stdout, stderr = cppcheck(args)
38603858
assert stdout == ''
38613859
assert stderr.splitlines() == [
3862-
f'{lib_file}:-1:0: information: Unmatched suppression: error [unmatchedSuppression]',
3863-
f'{lib_file}:-1:0: information: Unmatched suppression: error2 [unmatchedSuppression]',
3864-
f'{lib_file}:-1:0: information: Unmatched suppression: error3 [unmatchedSuppression]',
3865-
f'{lib_file}:-1:0: information: Unmatched suppression: error4 [unmatchedSuppression]',
3866-
f'{lib_file}:-1:0: information: Unmatched suppression: error5 [unmatchedSuppression]',
3867-
f'{lib_file}:-1:0: information: Unmatched suppression: error6 [unmatchedSuppression]'
3860+
f'{lib_file}:0:0: information: Unmatched suppression: error [unmatchedSuppression]',
3861+
f'{lib_file}:0:0: information: Unmatched suppression: error2 [unmatchedSuppression]',
3862+
f'{lib_file}:0:0: information: Unmatched suppression: error3 [unmatchedSuppression]',
3863+
f'{lib_file}:0:0: information: Unmatched suppression: error4 [unmatchedSuppression]',
3864+
f'{lib_file}:0:0: information: Unmatched suppression: error5 [unmatchedSuppression]',
3865+
f'{lib_file}:0:0: information: Unmatched suppression: error6 [unmatchedSuppression]'
38683866
]
38693867
assert ret == 0, stdout
38703868

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)