commit 572dcc2b8397b149fab16a2e885598b59691ad47
parent c77ea0210b31460d8846ddba8132765648ce35d8
Author: Robert Ransom <rransom.8774@gmail.com>
Date: Sun, 20 May 2012 12:51:18 +0000
util/estrtol: Also check for out-of-range values using errno
Diffstat:
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/util/estrtol.c b/util/estrtol.c
@@ -1,4 +1,5 @@
/* See LICENSE file for copyright and license details. */
+#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include "../util.h"
@@ -9,8 +10,9 @@ estrtol(const char *s, int base)
char *end;
long n;
+ errno = 0;
n = strtol(s, &end, base);
- if(*end != '\0') {
+ if(*end != '\0' || errno != 0) {
if(base == 0)
eprintf("%s: not an integer\n", s);
else