summaryrefslogtreecommitdiffstats
path: root/Source/cmakemain.cxx
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2019-05-03 15:45:22 (GMT)
committerKitware Robot <kwrobot@kitware.com>2019-05-03 15:45:32 (GMT)
commit9713154cf609691dfe9b8484c16cc034ea52d799 (patch)
treeb764e9b384727019d418b4263c6c068905710b42 /Source/cmakemain.cxx
parentcd285b749615c64e72ddadda0ba014c91829529c (diff)
parent6ad699358b6b421da6c49cf540b30eb8b0a3a996 (diff)
downloadCMake-9713154cf609691dfe9b8484c16cc034ea52d799.zip
CMake-9713154cf609691dfe9b8484c16cc034ea52d799.tar.gz
CMake-9713154cf609691dfe9b8484c16cc034ea52d799.tar.bz2
Merge topic 'jobs-positive-value'
6ad699358b cmake: --build -j <jobs> should not accept 0. Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !3255
Diffstat (limited to 'Source/cmakemain.cxx')
-rw-r--r--Source/cmakemain.cxx24
1 files changed, 21 insertions, 3 deletions
diff --git a/Source/cmakemain.cxx b/Source/cmakemain.cxx
index 5631d10..49d160c 100644
--- a/Source/cmakemain.cxx
+++ b/Source/cmakemain.cxx
@@ -24,6 +24,7 @@
#endif
#include <cassert>
+#include <climits>
#include <ctype.h>
#include <iostream>
#include <string.h>
@@ -69,7 +70,7 @@ static const char* cmDocumentationUsageNote[][2] = {
" --config <cfg> = For multi-configuration tools, choose <cfg>.\n" \
" --clean-first = Build target 'clean' first, then build.\n" \
" (To clean only, use --target 'clean'.)\n" \
- " --verbose, -v = Enable verbose output - if supported - including\n" \
+ " --verbose, -v = Enable verbose output - if supported - including\n" \
" the build commands to be executed. \n" \
" -- = Pass remaining options to the native tool.\n"
@@ -395,7 +396,14 @@ int extract_job_number(int& index, char const* current, char const* next,
if (jobString.empty()) {
jobs = cmake::DEFAULT_BUILD_PARALLEL_LEVEL;
} else if (cmSystemTools::StringToULong(jobString.c_str(), &numJobs)) {
- jobs = int(numJobs);
+ if (numJobs == 0) {
+ std::cerr
+ << "The <jobs> value requires a positive integer argument.\n\n";
+ } else if (numJobs > INT_MAX) {
+ std::cerr << "The <jobs> value is too large.\n\n";
+ } else {
+ jobs = int(numJobs);
+ }
} else {
std::cerr << "'" << command.substr(0, len_of_flag) << "' invalid number '"
<< jobString << "' given.\n\n";
@@ -507,7 +515,17 @@ static int do_build(int ac, char const* const* av)
} else {
unsigned long numJobs = 0;
if (cmSystemTools::StringToULong(parallel.c_str(), &numJobs)) {
- jobs = int(numJobs);
+ if (numJobs == 0) {
+ std::cerr << "The CMAKE_BUILD_PARALLEL_LEVEL environment variable "
+ "requires a positive integer argument.\n\n";
+ dir.clear();
+ } else if (numJobs > INT_MAX) {
+ std::cerr << "The CMAKE_BUILD_PARALLEL_LEVEL environment variable "
+ "is too large.\n\n";
+ dir.clear();
+ } else {
+ jobs = int(numJobs);
+ }
} else {
std::cerr << "'CMAKE_BUILD_PARALLEL_LEVEL' environment variable\n"
<< "invalid number '" << parallel << "' given.\n\n";