Skip to content

Commit

Permalink
Fix #12144 (Error messages from addons has the wrong file0) (danmar#5621
Browse files Browse the repository at this point in the history
)
  • Loading branch information
danmar authored Nov 4, 2023
1 parent 72a3617 commit 0dc53ac
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
14 changes: 7 additions & 7 deletions lib/cppcheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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<std::string> f{dumpFile};
executeAddons(f);
executeAddons(f, file0);
}
}

void CppCheck::executeAddons(const std::vector<std::string>& files)
void CppCheck::executeAddons(const std::vector<std::string>& files, const std::string& file0)
{
if (mSettings.addons.empty() || files.empty())
return;
Expand Down Expand Up @@ -1444,7 +1444,7 @@ void CppCheck::executeAddons(const std::vector<std::string>& files)
}
else if (!mSettings.severity.isEnabled(errmsg.severity))
continue;
errmsg.file0 = ((files.size() == 1) ? files[0] : "");
errmsg.file0 = file0;

reportErr(errmsg);
}
Expand All @@ -1463,7 +1463,7 @@ void CppCheck::executeAddonsWholeProgram(const std::map<std::string, std::size_t
}

try {
executeAddons(ctuInfoFiles);
executeAddons(ctuInfoFiles, "");
} catch (const InternalError& e) {
const ErrorMessage errmsg = ErrorMessage::fromInternalError(e, nullptr, "", "Bailing out from analysis: Whole program analysis failed");
reportErr(errmsg);
Expand Down
4 changes: 2 additions & 2 deletions lib/cppcheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,8 @@ class CPPCHECKLIB CppCheck : ErrorLogger {
/**
* Execute addons
*/
void executeAddons(const std::vector<std::string>& files);
void executeAddons(const std::string &dumpFile);
void executeAddons(const std::vector<std::string>& files, const std::string& file0);
void executeAddons(const std::string &dumpFile, const std::string& file0);

/**
* Execute addons
Expand Down
12 changes: 12 additions & 0 deletions test/cli/test-other.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 0dc53ac

Please sign in to comment.