Skip to content

Commit

Permalink
Fix #13047 (....)
Browse files Browse the repository at this point in the history
  • Loading branch information
danmar committed Aug 29, 2024
1 parent e6b0081 commit c3f0b3e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
9 changes: 7 additions & 2 deletions cli/cmdlineparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,7 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
else if (std::strncmp(argv[i], "--error-exitcode=", 17) == 0) {
if (!parseNumberArg(argv[i], 17, mSettings.exitCode))
return Result::Fail;
mSettings.errorExitCode0 = (!mSettings.safety && mSettings.exitCode == 0);
}

// Exception handling inside cppcheck client
Expand Down Expand Up @@ -996,8 +997,10 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
"bughunting",
"safety"};

if (std::strcmp(argv[i], "--premium=safety") == 0)
if (std::strcmp(argv[i], "--premium=safety") == 0) {
mSettings.safety = true;
mSettings.errorExitCode0 = false;
}
if (!mSettings.premiumArgs.empty())
mSettings.premiumArgs += " ";
const std::string p(argv[i] + 10);
Expand Down Expand Up @@ -1222,8 +1225,10 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
}

// Safety certified behavior
else if (std::strcmp(argv[i], "--safety") == 0)
else if (std::strcmp(argv[i], "--safety") == 0) {
mSettings.safety = true;
mSettings.errorExitCode0 = false;
}

// show timing information..
else if (std::strncmp(argv[i], "--showtime=", 11) == 0) {
Expand Down
6 changes: 5 additions & 1 deletion cli/cppcheckexecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,12 @@ int CppCheckExecutor::check_internal(const Settings& settings) const
stdLogger.reportErr(ErrorMessage::getXMLFooter());
}

if (settings.safety && (stdLogger.hasCriticalErrors() || returnValue != 0))
if (settings.safety && stdLogger.hasCriticalErrors()) {
const bool isSafeVersion = endsWith(settings.cppcheckCfgProductName, 'S') || endsWith(settings.cppcheckCfgProductName, 's');
if (settings.errorExitCode0 && !isSafeVersion)
return EXIT_SUCCESS;
return EXIT_FAILURE;
}

if (returnValue)
return settings.exitCode;
Expand Down
3 changes: 3 additions & 0 deletions lib/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,9 @@ class CPPCHECKLIB WARN_UNUSED Settings {
Default value is 0. */
int exitCode{};

/** @brief was --error-exitcode=0 used on the command line? */
bool errorExitCode0{};

/** @brief List of --file-filter for analyzing special files */
std::vector<std::string> fileFilters;

Expand Down

0 comments on commit c3f0b3e

Please sign in to comment.