diff --git a/cli/cmdlineparser.cpp b/cli/cmdlineparser.cpp index 644586bbc2d..06543326757 100644 --- a/cli/cmdlineparser.cpp +++ b/cli/cmdlineparser.cpp @@ -969,7 +969,8 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a } // Special Cppcheck Premium options - else if (std::strncmp(argv[i], "--premium=", 10) == 0 && isCppcheckPremium()) { + else if ((std::strncmp(argv[i], "--premium=", 10) == 0 || std::strncmp(argv[i], "--premium-", 10) == 0) && isCppcheckPremium()) { + // valid options --premium=.. const std::set valid{ "autosar", "cert-c-2016", @@ -983,6 +984,11 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a "misra-cpp-2023", "bughunting", "safety"}; + // valid options --premium-..= + const std::set valid2{ + "cert-c-int-precision", + "license-file" + }; if (std::strcmp(argv[i], "--premium=safety-off") == 0) { mSettings.safety = false; @@ -993,8 +999,9 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a if (!mSettings.premiumArgs.empty()) mSettings.premiumArgs += " "; const std::string p(argv[i] + 10); - if (!valid.count(p) && !startsWith(p, "cert-c-int-precision=")) { - mLogger.printError("invalid --premium option '" + p + "'."); + const std::string p2(p.find('=') != std::string::npos ? p.substr(0, p.find('=')) : ""); + if (!valid.count(p) && !valid2.count(p2)) { + mLogger.printError("invalid --premium option '" + (p2.empty() ? p : p2) + "'."); return Result::Fail; } mSettings.premiumArgs += "--" + p; diff --git a/test/testcmdlineparser.cpp b/test/testcmdlineparser.cpp index 3427bb54c3c..08dbe16b4db 100644 --- a/test/testcmdlineparser.cpp +++ b/test/testcmdlineparser.cpp @@ -213,6 +213,8 @@ class TestCmdlineParser : public TestFixture { TEST_CASE(premiumOptions3); TEST_CASE(premiumOptions4); TEST_CASE(premiumOptions5); + TEST_CASE(premiumOptionsCertCIntPrecision); + TEST_CASE(premiumOptionsLicenseFile); TEST_CASE(premiumOptionsInvalid1); TEST_CASE(premiumOptionsInvalid2); TEST_CASE(premiumSafety); @@ -1290,6 +1292,22 @@ class TestCmdlineParser : public TestFixture { ASSERT_EQUALS(false, settings->severity.isEnabled(Severity::warning)); } + void premiumOptionsCertCIntPrecision() { + REDIRECT; + asPremium(); + const char * const argv[] = {"cppcheck", "--premium-cert-c-int-precision=12", "file.c"}; + ASSERT_EQUALS_ENUM(CmdLineParser::Result::Success, parser->parseFromArgs(3, argv)); + ASSERT_EQUALS("--cert-c-int-precision=12", settings->premiumArgs); + } + + void premiumOptionsLicenseFile() { + REDIRECT; + asPremium(); + const char * const argv[] = {"cppcheck", "--premium-license-file=file.lic", "file.c"}; + ASSERT_EQUALS_ENUM(CmdLineParser::Result::Success, parser->parseFromArgs(3, argv)); + ASSERT_EQUALS("--license-file=file.lic", settings->premiumArgs); + } + void premiumOptionsInvalid1() { REDIRECT; asPremium();