Paranoid str to int check

This commit is contained in:
Andrey Skobtsov 2020-03-06 19:30:50 +03:00
parent ca7b5a3a05
commit 50c603a74c

View File

@ -105,8 +105,12 @@ namespace DB {
return false;
str[MAX_LENGTH - 1] = '\0';
// todo: change to `strtol`
result = atoi(str);
long value = strtol(str, nullptr, 10);
// the only way to be incorrect is to not be a number
if (value == 0 && errno != 0)
return false;
result = static_cast<int>(value);
return true;
}