Skip to content

Commit

Permalink
common/strtol.cc: Get error testing also to work on FreeBSD
Browse files Browse the repository at this point in the history
 - change order of testing
 - But report the same error types.
 - Changed to report for the last error since the value is there but
   not allowed characters follow.

Error found by: run-cli-tests, because the wrong string was returned.

Signed-off-by: Willem Jan Withagen <wjw@digiware.nl>
  • Loading branch information
wjwithagen committed Nov 17, 2016
1 parent eb8b4c8 commit ce47832
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/common/strtol.cc
Expand Up @@ -28,6 +28,13 @@ long long strict_strtoll(const char *str, int base, std::string *err)
errno = 0; /* To distinguish success/failure after call (see man page) */
long long ret = strtoll(str, &endptr, base);

if (endptr == str) {
errStr = "Expected option value to be integer, got '";
errStr.append(str);
errStr.append("'");
*err = errStr;
return 0;
}
if ((errno == ERANGE && (ret == LLONG_MAX || ret == LLONG_MIN))
|| (errno != 0 && ret == 0)) {
errStr = "The option value '";
Expand All @@ -37,18 +44,11 @@ long long strict_strtoll(const char *str, int base, std::string *err)
*err = errStr;
return 0;
}
if (endptr == str) {
errStr = "Expected option value to be integer, got '";
errStr.append(str);
errStr.append("'");
*err = errStr;
return 0;
}
if (*endptr != '\0') {
errStr = "The option value '";
errStr.append(str);
errStr.append("'");
errStr.append(" seems to be invalid");
errStr.append(" contains invalid digits");
*err = errStr;
return 0;
}
Expand Down

0 comments on commit ce47832

Please sign in to comment.