builtin_test.cpp: check for ERANGE and special fish_wcstoll errno

We were not parsing an in-range number when we claimed we were,
and were thus failing to error with invalid numbers and returned
a wrong test result. Fixed #5414

Also, provide the detail we can for the other error cases.
This commit is contained in:
Aaron Gyes 2018-12-14 11:42:23 -08:00
parent c1be3284c1
commit 4aa069a8ff

View File

@ -657,7 +657,7 @@ static bool parse_number(const wcstring &arg, number_t *number, wcstring_list_t
// invalid (e.g. not a representable integer). // invalid (e.g. not a representable integer).
*number = number_t{integral, 0.0}; *number = number_t{integral, 0.0};
return true; return true;
} else if (got_float) { } else if (got_float && errno != ERANGE) {
// Here we parsed an (in range) floating point value that could not be parsed as an integer. // Here we parsed an (in range) floating point value that could not be parsed as an integer.
// Break the floating point value into base and delta. Ensure that base is <= the floating // Break the floating point value into base and delta. Ensure that base is <= the floating
// point value. // point value.
@ -667,7 +667,11 @@ static bool parse_number(const wcstring &arg, number_t *number, wcstring_list_t
return true; return true;
} else { } else {
// We could not parse a float or an int. // We could not parse a float or an int.
errors.push_back(format_string(_(L"invalid number '%ls'"), arg.c_str())); // Check for special fish_wcsto* value or show standard EINVAL/ERANGE error.
if (errno == -1)
errors.push_back(format_string(_(L"Integer %lld in '%ls' followed by non-digit"), integral, argcs));
else
errors.push_back(format_string(L"%s: '%ls'", strerror(errno), argcs));
return false; return false;
} }
} }