[hackers] [sbase] util/estrtol: Also check for out-of-range values using errno || Robert Ransom
changeset: 122:3e0195c79f87
user: Robert Ransom <rransom.8774_AT_gmail.com>
date: Sun May 20 12:51:18 2012 +0000
files: util/estrtol.c
description:
util/estrtol: Also check for out-of-range values using errno
diff -r 795867539759 -r 3e0195c79f87 util/estrtol.c
--- a/util/estrtol.c Wed May 16 12:14:02 2012 +0000
+++ b/util/estrtol.c Sun May 20 12:51:18 2012 +0000
_AT_@ -1,4 +1,5 @@
/* See LICENSE file for copyright and license details. */
+#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include "../util.h"
_AT_@ -9,8 +10,9 @@
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
Received on Tue May 22 2012 - 13:08:45 CEST
This archive was generated by hypermail 2.3.0
: Tue May 22 2012 - 13:12:07 CEST