From c31da9332d2e9005baa70bd35a88826334aea0e1 Mon Sep 17 00:00:00 2001 From: Johannes Löthberg Date: Wed, 5 Nov 2014 08:51:07 +0100 Subject: yawa.c: nuke atoi --- src/yawa.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/yawa.c b/src/yawa.c index d6219e6..7d67fac 100644 --- a/src/yawa.c +++ b/src/yawa.c @@ -61,7 +61,6 @@ parse_opt (int key, char *arg, struct argp_state *state) fprintf(stderr, "No digits were found\n"); exit(-2); } - break; case 'c': arguments->clear = true; @@ -92,7 +91,19 @@ parse_opt (int key, char *arg, struct argp_state *state) break; case 'A': arguments->alpha = true; - arguments->alpha_amount = atoi(arg); + val = strtol(arg, &endptr, 10); + arguments->alpha_amount = (int)val; + + if ((errno == ERANGE && (val == LONG_MAX || val == LONG_MIN)) + || (errno != 0 && val == 0)) { + perror("strtol"); + exit(-2); + } + + if (endptr == arg) { + fprintf(stderr, "No digits were found\n"); + exit(-2); + } break; default: return ARGP_ERR_UNKNOWN; -- cgit v1.2.3-70-g09d2