diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index 5a270d938ca..7d93bc78192 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -1682,8 +1682,14 @@ void CppCheck::executeAddons(const std::vector& files, const std::s if (isCtuInfo && addonInfo.name != "misra" && !addonInfo.ctu) continue; - const std::vector results = - executeAddon(addonInfo, mSettings.addonPython, fileList.empty() ? files[0] : fileList, mSettings.premiumArgs, mExecuteCommand); + std::vector 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"); + mErrorLogger.reportErr(errmsg); + continue; + } const bool misraC2023 = mSettings.premiumArgs.find("--misra-c-2023") != std::string::npos; diff --git a/test/cli/whole-program_test.py b/test/cli/whole-program_test.py index c8115f06d19..29dc94cb7e9 100644 --- a/test/cli/whole-program_test.py +++ b/test/cli/whole-program_test.py @@ -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): + # 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