From: Andre Noll Date: Sat, 5 Sep 2015 11:01:18 +0000 (+0200) Subject: string.c: Kill E_STRTOLL. X-Git-Tag: v0.5.6~102 X-Git-Url: http://git.tue.mpg.de/?a=commitdiff_plain;h=ad0a32acc373428d38e6b0f2f244ac3c31eea7c5;p=paraslash.git string.c: Kill E_STRTOLL. This error code is unnecessary because para_atoi64() returns it only if strtoll(3) did not perform any conversion and we have already a more descriptive error code for this case: E_ATOI_NO_DIGITS. Two new comments to para_atoi64() explain this in detail. --- diff --git a/error.h b/error.h index 28ac9552..57f581cf 100644 --- a/error.h +++ b/error.h @@ -386,7 +386,6 @@ extern const char **para_errlist[]; #define STRING_ERRORS \ PARA_ERROR(ATOI_OVERFLOW, "value too large"), \ - PARA_ERROR(STRTOLL, "unknown strtoll error"), \ PARA_ERROR(ATOI_NO_DIGITS, "no digits found in string"), \ PARA_ERROR(ATOI_JUNK_AT_END, "further characters after number"), \ PARA_ERROR(SIZE_PREFIX, "bad size prefix"), \ diff --git a/string.c b/string.c index f8b64b77..c3528515 100644 --- a/string.c +++ b/string.c @@ -562,10 +562,18 @@ int para_atoi64(const char *str, int64_t *value) tmp = strtoll(str, &endptr, 10); if (errno == ERANGE && (tmp == LLONG_MAX || tmp == LLONG_MIN)) return -E_ATOI_OVERFLOW; - if (errno != 0 && tmp == 0) /* other error */ - return -E_STRTOLL; + /* + * If there were no digits at all, strtoll() stores the original value + * of str in *endptr. + */ if (endptr == str) return -E_ATOI_NO_DIGITS; + /* + * The implementation may also set errno and return 0 in case no + * conversion was performed. + */ + if (errno != 0 && tmp == 0) + return -E_ATOI_NO_DIGITS; if (*endptr != '\0') /* Further characters after number */ return -E_ATOI_JUNK_AT_END; *value = tmp;