From 4aa069a8ff14f62c6329b7afbf404a65cf289ca5 Mon Sep 17 00:00:00 2001 From: Aaron Gyes Date: Fri, 14 Dec 2018 11:42:23 -0800 Subject: [PATCH] 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. --- src/builtin_test.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/builtin_test.cpp b/src/builtin_test.cpp index 07ae926b9..07aa37356 100644 --- a/src/builtin_test.cpp +++ b/src/builtin_test.cpp @@ -657,7 +657,7 @@ static bool parse_number(const wcstring &arg, number_t *number, wcstring_list_t // invalid (e.g. not a representable integer). *number = number_t{integral, 0.0}; 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. // Break the floating point value into base and delta. Ensure that base is <= the floating // point value. @@ -667,7 +667,11 @@ static bool parse_number(const wcstring &arg, number_t *number, wcstring_list_t return true; } else { // 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; } }