From ad0a32acc373428d38e6b0f2f244ac3c31eea7c5 Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Sat, 5 Sep 2015 13:01:18 +0200 Subject: [PATCH] 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. --- error.h | 1 - string.c | 12 ++++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) 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; -- 2.39.2