Skip to content

Commit 48c5687

Browse files
committed
refs #13982 - cppcheck.cpp: do not crash if mExecuteCommand is empty
1 parent 9b11b6b commit 48c5687

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

lib/cppcheck.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,9 @@ static std::vector<picojson::value> executeAddon(const AddonInfo &addonInfo,
432432
const std::string &premiumArgs,
433433
const CppCheck::ExecuteCmdFn &executeCommand)
434434
{
435+
if (!executeCommand)
436+
throw InternalError(nullptr, "Failed to execute addon - no command callback provided");
437+
435438
std::string pythonExe;
436439

437440
if (!addonInfo.executable.empty())
@@ -686,6 +689,11 @@ unsigned int CppCheck::checkClang(const FileWithDetails &file, int fileIndex)
686689
mErrorLogger.reportOut(exe + " " + args2, Color::Reset);
687690
}
688691

692+
if (!mExecuteCommand) {
693+
std::cerr << "Failed to execute '" << exe << " " << args2 << " " << redirect2 << "' - (no command callback provided)" << std::endl;
694+
return 0; // TODO: report as failure?
695+
}
696+
689697
std::string output2;
690698
const int exitcode = mExecuteCommand(exe,split(args2),redirect2,output2);
691699
if (mSettings.debugClangOutput) {
@@ -1954,6 +1962,11 @@ void CppCheck::analyseClangTidy(const FileSettings &fileSettings)
19541962
}
19551963
#endif
19561964

1965+
if (!mExecuteCommand) {
1966+
std::cerr << "Failed to execute '" << exe << "' (no command callback provided)" << std::endl;
1967+
return;
1968+
}
1969+
19571970
// TODO: log this call
19581971
// TODO: get rid of hard-coded checks
19591972
const std::string args = "-quiet -checks=*,-clang-analyzer-*,-llvm* \"" + fileSettings.filename() + "\" -- " + allIncludes + allDefines;

0 commit comments

Comments
 (0)