]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
string.c: Kill E_STRTOLL.
authorAndre Noll <maan@tuebingen.mpg.de>
Sat, 5 Sep 2015 11:01:18 +0000 (13:01 +0200)
committerAndre Noll <maan@tuebingen.mpg.de>
Sun, 20 Sep 2015 18:32:53 +0000 (20:32 +0200)
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
string.c

diff --git a/error.h b/error.h
index 28ac9552315689124f2bfa1de0e50f874d2e9e61..57f581cf3fc405c46b919adfc6c4808c05424c82 100644 (file)
--- 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"), \
 
 #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"), \
        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"), \
index f8b64b77c08d0c109c62129bdfeac04b775b3d6b..c35285153fdadf031fafb544aea4affdf066a86d 100644 (file)
--- 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;
        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;
        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;
        if (*endptr != '\0') /* Further characters after number */
                return -E_ATOI_JUNK_AT_END;
        *value = tmp;