Skip to content

Commit ee8e09c

Browse files
committed
Fix parsing of -ntasks argument
1 parent 41b4db0 commit ee8e09c

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

src/bitcoin-util.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,15 @@ static int Grind(const std::vector<std::string>& args, std::string& strPrint)
133133
std::vector<std::thread> threads;
134134
uint16_t n_tasks = std::max(1u, std::thread::hardware_concurrency());
135135
if(gArgs.IsArgSet("-ntasks")) {
136-
if(!ParseUInt16(gArgs.GetArg("-ntasks", "1"), &n_tasks)) {
137-
strPrint = strprintf("Argument to -ntasks should be a number, found %s\n", *gArgs.GetArg("-ntasks"));
136+
const auto ntasks_str = *gArgs.GetArg("-ntasks");
137+
try {
138+
n_tasks = std::stoi(ntasks_str);
139+
if (n_tasks <= 0 || n_tasks > std::thread::hardware_concurrency()) {
140+
strPrint = strprintf("Argument to -ntasks must be a positive number less than or equal to the number of cores %u, found %s\n", std::thread::hardware_concurrency(), ntasks_str);
141+
return EXIT_FAILURE;
142+
}
143+
} catch (const std::exception&) {
144+
strPrint = strprintf("Argument to -ntasks should be a number, found %s\n", ntasks_str);
138145
return EXIT_FAILURE;
139146
}
140147
}

0 commit comments

Comments
 (0)