Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions lib/cppcheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1682,8 +1682,14 @@ void CppCheck::executeAddons(const std::vector<std::string>& files, const std::s
if (isCtuInfo && addonInfo.name != "misra" && !addonInfo.ctu)
continue;

const std::vector<picojson::value> results =
executeAddon(addonInfo, mSettings.addonPython, fileList.empty() ? files[0] : fileList, mSettings.premiumArgs, mExecuteCommand);
std::vector<picojson::value> results;
try {
results = executeAddon(addonInfo, mSettings.addonPython, fileList.empty() ? files[0] : fileList, mSettings.premiumArgs, mExecuteCommand);
} catch (const InternalError& e) {
const ErrorMessage errmsg = ErrorMessage::fromInternalError(e, nullptr, file0, "Bailing out from analysis: Addon '" + addonInfo.name + "' failed");
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name we have in addonInfo.name looks like a placeholder

mErrorLogger.reportErr(errmsg);
continue;
}

const bool misraC2023 = mSettings.premiumArgs.find("--misra-c-2023") != std::string::npos;

Expand Down
15 changes: 15 additions & 0 deletions test/cli/whole-program_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,3 +358,18 @@ def test_checkclass_project_builddir_j(tmpdir):
build_dir = os.path.join(tmpdir, 'b1')
os.mkdir(build_dir)
__test_checkclass_project(tmpdir, ['-j2', '--cppcheck-build-dir={}'.format(build_dir)])


def test_ctu_fail(tmpdir):
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file only contain tests which relate to the whole-program folder so this should be added the other_test.py.

# 13440 - handle InternalError exception during whole program analysis

with open(tmpdir / 'foo.json', 'wt') as f:
f.write('{ "executable": "notexist", "ctu": true }')

test_file = tmpdir / 'test.c'
with open(test_file, 'wt') as f:
f.write(';\n')

_, _, stderr = cppcheck(['--addon=foo.json', '--template=daca2', 'test.c'], cwd=tmpdir)
last_line = stderr.strip().splitlines()[-1]
assert ''':0:0: error: Bailing out from analysis: Addon 'foo.json' failed: Failed to execute addon 'foo.json' - exitcode is 127 [internalError]''' == last_line