diff --git a/cli/cppcheckexecutor.cpp b/cli/cppcheckexecutor.cpp index 4f74bccbd5e..77b80b5c3c7 100644 --- a/cli/cppcheckexecutor.cpp +++ b/cli/cppcheckexecutor.cpp @@ -327,7 +327,7 @@ static bool reportUnmatchedSuppressions(const std::list callStack; if (!s.fileName.empty()) { - callStack.emplace_back(s.fileName, s.lineNumber, 0); + callStack.emplace_back(s.fileName, s.lineNumber == -1 ? 0 : s.lineNumber, 0); // TODO: get rid of s.lineNumber == -1 hack } const std::string unmatchedSuppressionId = s.isPolyspace ? "unmatchedPolyspaceSuppression" : "unmatchedSuppression"; errorLogger.reportErr(::ErrorMessage(std::move(callStack), "", Severity::information, "Unmatched suppression: " + s.errorId, unmatchedSuppressionId, Certainty::normal)); diff --git a/test/cli/other_test.py b/test/cli/other_test.py index 1a80b06d929..121d0ac65cb 100644 --- a/test/cli/other_test.py +++ b/test/cli/other_test.py @@ -3371,11 +3371,10 @@ def test_suppress_unmatched_wildcard(tmp_path): # #13660 exitcode, stdout, stderr = cppcheck(args, cwd=tmp_path) assert exitcode == 0, stdout assert stdout.splitlines() == [] - # TODO: invalid locations - see #13659 assert stderr.splitlines() == [ - 'test*.c:-1:0: information: Unmatched suppression: id [unmatchedSuppression]', - 'test*.c:-1:0: information: Unmatched suppression: id2 [unmatchedSuppression]', - 'tes?.c:-1:0: information: Unmatched suppression: id2 [unmatchedSuppression]' + 'test*.c:0:0: information: Unmatched suppression: id [unmatchedSuppression]', + 'test*.c:0:0: information: Unmatched suppression: id2 [unmatchedSuppression]', + 'tes?.c:0:0: information: Unmatched suppression: id2 [unmatchedSuppression]' ] @@ -3400,12 +3399,11 @@ def test_suppress_unmatched_wildcard_unchecked(tmp_path): exitcode, stdout, stderr = cppcheck(args, cwd=tmp_path) assert exitcode == 0, stdout assert stdout.splitlines() == [] - # TODO: invalid locations - see #13659 assert stderr.splitlines() == [ - 'test*.c:-1:0: information: Unmatched suppression: id [unmatchedSuppression]', - 'tes?.c:-1:0: information: Unmatched suppression: id [unmatchedSuppression]', - '*:-1:0: information: Unmatched suppression: id2 [unmatchedSuppression]', - 'test*.c:-1:0: information: Unmatched suppression: * [unmatchedSuppression]' + 'test*.c:0:0: information: Unmatched suppression: id [unmatchedSuppression]', + 'tes?.c:0:0: information: Unmatched suppression: id [unmatchedSuppression]', + '*:0:0: information: Unmatched suppression: id2 [unmatchedSuppression]', + 'test*.c:0:0: information: Unmatched suppression: * [unmatchedSuppression]' ] @@ -3859,12 +3857,12 @@ def test_unmatched_file(tmp_path): # #14248 / #14249 ret, stdout, stderr = cppcheck(args) assert stdout == '' assert stderr.splitlines() == [ - f'{lib_file}:-1:0: information: Unmatched suppression: error [unmatchedSuppression]', - f'{lib_file}:-1:0: information: Unmatched suppression: error2 [unmatchedSuppression]', - f'{lib_file}:-1:0: information: Unmatched suppression: error3 [unmatchedSuppression]', - f'{lib_file}:-1:0: information: Unmatched suppression: error4 [unmatchedSuppression]', - f'{lib_file}:-1:0: information: Unmatched suppression: error5 [unmatchedSuppression]', - f'{lib_file}:-1:0: information: Unmatched suppression: error6 [unmatchedSuppression]' + f'{lib_file}:0:0: information: Unmatched suppression: error [unmatchedSuppression]', + f'{lib_file}:0:0: information: Unmatched suppression: error2 [unmatchedSuppression]', + f'{lib_file}:0:0: information: Unmatched suppression: error3 [unmatchedSuppression]', + f'{lib_file}:0:0: information: Unmatched suppression: error4 [unmatchedSuppression]', + f'{lib_file}:0:0: information: Unmatched suppression: error5 [unmatchedSuppression]', + f'{lib_file}:0:0: information: Unmatched suppression: error6 [unmatchedSuppression]' ] assert ret == 0, stdout diff --git a/test/testsuppressions.cpp b/test/testsuppressions.cpp index e8ebc4c4702..2b87cdad42b 100644 --- a/test/testsuppressions.cpp +++ b/test/testsuppressions.cpp @@ -542,7 +542,7 @@ class TestSuppressions : public TestFixture { " b++;\n" "}\n", "uninitvar:test.cpp")); - ASSERT_EQUALS("[test.cpp]: (information) Unmatched suppression: uninitvar [unmatchedSuppression]\n", errout_str()); + ASSERT_EQUALS("[test.cpp:0:0]: (information) Unmatched suppression: uninitvar [unmatchedSuppression]\n", errout_str()); // suppress all for this file only ASSERT_EQUALS(0, (this->*check)("void f() {\n" @@ -558,7 +558,7 @@ class TestSuppressions : public TestFixture { " b++;\n" "}\n", "*:test.cpp")); - ASSERT_EQUALS("[test.cpp]: (information) Unmatched suppression: * [unmatchedSuppression]\n", errout_str()); + ASSERT_EQUALS("[test.cpp:0:0]: (information) Unmatched suppression: * [unmatchedSuppression]\n", errout_str()); // suppress uninitvar for this file and line ASSERT_EQUALS(0, (this->*check)("void f() {\n"