From 505ac4b27e9dd9406f18a07f2c5d3e77ac5e1dfa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Wed, 28 Jun 2023 16:23:53 +0200 Subject: [PATCH] fix --- cli/cmdlineparser.cpp | 2 +- cli/cmdlineparser.h | 5 ++--- test/testcmdlineparser.cpp | 2 +- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/cli/cmdlineparser.cpp b/cli/cmdlineparser.cpp index acd5a642d72..d76edbf9114 100644 --- a/cli/cmdlineparser.cpp +++ b/cli/cmdlineparser.cpp @@ -263,7 +263,7 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[]) } else if (std::strncmp(argv[i], "--checks-max-time=", 18) == 0) { - if (!parseNumberArg(argv[i], 18, mSettings.checksMaxTime)) + if (!parseNumberArg(argv[i], 18, mSettings.checksMaxTime, true)) return false; } diff --git a/cli/cmdlineparser.h b/cli/cmdlineparser.h index efcdb3f5d52..d12a5247b64 100644 --- a/cli/cmdlineparser.h +++ b/cli/cmdlineparser.h @@ -123,9 +123,8 @@ class CmdLineParser { private: bool isCppcheckPremium() const; - // TODO: get rid of is_signed template - static bool parseNumberArg(const char* const arg, std::size_t offset, T& num, bool is_signed = false) + static bool parseNumberArg(const char* const arg, std::size_t offset, T& num, bool mustBePositive = false) { T tmp; std::string err; @@ -133,7 +132,7 @@ class CmdLineParser { printError("argument to '" + std::string(arg, offset) + "' is not valid - " + err + "."); return false; } - if (is_signed && tmp < 0) { + if (mustBePositive && tmp < 0) { printError("argument to '" + std::string(arg, offset) + "' needs to be a positive integer."); return false; } diff --git a/test/testcmdlineparser.cpp b/test/testcmdlineparser.cpp index 09fa604a6e7..fffa19f5ff7 100644 --- a/test/testcmdlineparser.cpp +++ b/test/testcmdlineparser.cpp @@ -1694,7 +1694,7 @@ class TestCmdlineParser : public TestFixture { REDIRECT; const char * const argv[] = {"cppcheck", "--checks-max-time=-1", "file.cpp"}; ASSERT(!defParser.parseFromArgs(3, argv)); - ASSERT_EQUALS("cppcheck: error: argument to '--checks-max-time=' is not valid - needs to be positive.\n", GET_REDIRECT_OUTPUT); + ASSERT_EQUALS("cppcheck: error: argument to '--checks-max-time=' needs to be a positive integer.\n", GET_REDIRECT_OUTPUT); } void checksMaxTimeInvalid() {