util/estrtol: Also check for out-of-range values using errno
This commit is contained in:
parent
c77ea0210b
commit
572dcc2b83
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user