more strict checking of valid input in utils::bounds() with new tests

This commit is contained in:
Axel Kohlmeyer
2021-03-14 17:59:00 -04:00
parent 1b409fbae8
commit 5d795130db
2 changed files with 45 additions and 54 deletions

View File

@ -394,9 +394,16 @@ template<typename TYPE>
void utils::bounds(const char *file, int line, const std::string &str,
bigint nmin, bigint nmax, TYPE &nlo, TYPE &nhi, Error *error)
{
size_t found = str.find_first_of("*");
nlo = nhi = -1;
// check for illegal charcters
size_t found = str.find_first_not_of("*-0123456789");
if (found != std::string::npos) {
if (error) error->all(file,line,fmt::format("Invalid range string: {}",str));
return;
}
found = str.find_first_of("*");
if (found == std::string::npos) { // contains no '*'
nlo = nhi = strtol(str.c_str(),nullptr,10);
} else if (str.size() == 1) { // is only '*'