util/estrtol: Also check for out-of-range values using errno

This commit is contained in:
Robert Ransom 2012-05-20 12:51:18 +00:00
parent c77ea0210b
commit 572dcc2b83

View File

@ -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