An empty string is not a valid number

Fixes #2284
This commit is contained in:
Maxime Coste 2018-08-04 11:10:19 +01:00
parent bf488338aa
commit 472a5732e2

View File

@ -100,6 +100,8 @@ Optional<int> str_to_int_ifp(StringView str)
bool negative = not str.empty() and str[0] == '-'; bool negative = not str.empty() and str[0] == '-';
if (negative) if (negative)
str = str.substr(1_byte); str = str.substr(1_byte);
if (str.empty())
return {};
unsigned int res = 0; unsigned int res = 0;
for (auto c : str) for (auto c : str)