diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index 2a8033b0e0b..ea6577b488b 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -522,7 +522,7 @@ unsigned int CppCheck::check(const std::string &path) } // run addons - executeAddons(dumpFile); + executeAddons(dumpFile, path); } catch (const InternalError &e) { const ErrorMessage errmsg = ErrorMessage::fromInternalError(e, nullptr, path, "Bailing out from analysis: Processing Clang AST dump failed"); @@ -967,7 +967,7 @@ unsigned int CppCheck::checkFile(const std::string& filename, const std::string fdump.close(); } - executeAddons(dumpFile); + executeAddons(dumpFile, Path::simplifyPath(filename)); } catch (const TerminateException &) { // Analysis is terminated @@ -1371,15 +1371,15 @@ void CppCheck::executeRules(const std::string &tokenlist, const Tokenizer &token } #endif -void CppCheck::executeAddons(const std::string& dumpFile) +void CppCheck::executeAddons(const std::string& dumpFile, const std::string& file0) { if (!dumpFile.empty()) { std::vector f{dumpFile}; - executeAddons(f); + executeAddons(f, file0); } } -void CppCheck::executeAddons(const std::vector& files) +void CppCheck::executeAddons(const std::vector& files, const std::string& file0) { if (mSettings.addons.empty() || files.empty()) return; @@ -1444,7 +1444,7 @@ void CppCheck::executeAddons(const std::vector& files) } else if (!mSettings.severity.isEnabled(errmsg.severity)) continue; - errmsg.file0 = ((files.size() == 1) ? files[0] : ""); + errmsg.file0 = file0; reportErr(errmsg); } @@ -1463,7 +1463,7 @@ void CppCheck::executeAddonsWholeProgram(const std::map& files); - void executeAddons(const std::string &dumpFile); + void executeAddons(const std::vector& files, const std::string& file0); + void executeAddons(const std::string &dumpFile, const std::string& file0); /** * Execute addons diff --git a/test/cli/test-other.py b/test/cli/test-other.py index 4a75ba61965..dffa3297f99 100644 --- a/test/cli/test-other.py +++ b/test/cli/test-other.py @@ -211,6 +211,18 @@ def test_execute_addon_failure_2(tmpdir): assert stderr == "{}:0:0: error: Bailing out from analysis: Checking file failed: Failed to execute addon 'naming' - exitcode is {} [internalError]\n\n^\n".format(test_file, ec) +def test_execute_addon_file0(tmpdir): + test_file = os.path.join(tmpdir, 'test.c') + with open(test_file, 'wt') as f: + f.write('void foo() {}\n') + + args = ['--xml', '--addon=misra', '--enable=style', test_file] + + _, _, stderr = cppcheck(args) + assert 'misra-c2012-8.2' in stderr + assert '.dump' not in stderr + + # TODO: find a test case which always fails @pytest.mark.skip def test_internal_error(tmpdir):