diff --git a/cli/cmdlineparser.cpp b/cli/cmdlineparser.cpp index 92b5c6a0a..f7826fef5 100644 --- a/cli/cmdlineparser.cpp +++ b/cli/cmdlineparser.cpp @@ -507,10 +507,17 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[]) printError("argument to '-j' is not valid - " + err + "."); return false; } - if (tmp > 10000) { - // This limit is here just to catch typos. If someone has - // need for more jobs, this value should be increased. - printError("argument for '-j' is allowed to be 10000 at max."); + if (tmp == 0) { + // TODO: implement get CPU logical core count and use that. + // Usually, -j 0 would mean "use all available cores," but + // if we get a 0, we just stall and don't do any work. + printError("argument for '-j' must be greater than 0."); + return false; + } + if (tmp > 1024) { + // Almost nobody has 1024 logical cores, but somebody out + // there does. + printError("argument for '-j' is allowed to be 1024 at max."); return false; } mSettings.jobs = tmp; diff --git a/test/testcmdlineparser.cpp b/test/testcmdlineparser.cpp index 5fdd05adc..d60006ccd 100644 --- a/test/testcmdlineparser.cpp +++ b/test/testcmdlineparser.cpp @@ -142,6 +142,7 @@ private: TEST_CASE(jobs2); TEST_CASE(jobsMissingCount); TEST_CASE(jobsInvalid); + TEST_CASE(jobsNoJobs); TEST_CASE(jobsTooBig); TEST_CASE(maxConfigs); TEST_CASE(maxConfigsMissingCount); @@ -1010,11 +1011,18 @@ private: ASSERT_EQUALS("cppcheck: error: argument to '-j' is not valid - not an integer.\n", GET_REDIRECT_OUTPUT); } + void jobsNoJobs() { + REDIRECT; + const char * const argv[] = {"cppcheck", "-j0", "file.cpp"}; + ASSERT(!parser->parseFromArgs(3, argv)); + ASSERT_EQUALS("cppcheck: error: argument for '-j' must be greater than 0.\n", GET_REDIRECT_OUTPUT); + } + void jobsTooBig() { REDIRECT; - const char * const argv[] = {"cppcheck", "-j10001", "file.cpp"}; + const char * const argv[] = {"cppcheck", "-j1025", "file.cpp"}; ASSERT(!parser->parseFromArgs(3, argv)); - ASSERT_EQUALS("cppcheck: error: argument for '-j' is allowed to be 10000 at max.\n", GET_REDIRECT_OUTPUT); + ASSERT_EQUALS("cppcheck: error: argument for '-j' is allowed to be 1024 at max.\n", GET_REDIRECT_OUTPUT); } void maxConfigs() {