]> granicus.if.org Git - mutt/commitdiff
mutt_atol: better error handling.
authorVincent Lefevre <vincent@vinc17.net>
Tue, 19 Jun 2018 07:45:29 +0000 (09:45 +0200)
committerVincent Lefevre <vincent@vinc17.net>
Tue, 19 Jun 2018 07:45:29 +0000 (09:45 +0200)
* Detect overflow on negative numbers too (< LONG_MIN).

* Distinguish between format error and number overflow as already
  expected (e.g. for pgp_timeout and smime_timeout).

lib.c

diff --git a/lib.c b/lib.c
index f008aae0493b819856bd1c9d1987870a572ee857..78e02dfe0379ee4b9313b8ef768ebdc1b483607b 100644 (file)
--- a/lib.c
+++ b/lib.c
@@ -1079,9 +1079,10 @@ int mutt_atol (const char *str, long *dst)
 
   errno = 0;
   *res = strtol (str, &e, 10);
-  if ((*res == LONG_MAX && errno == ERANGE) ||
-      (e && *e != '\0'))
+  if (e && *e != '\0')
     return -1;
+  if (errno == ERANGE)
+    return -2;
   return 0;
 }