aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJohannes Löthberg <johannes@kyriasis.com>2014-11-05 08:51:07 +0100
committerJohannes Löthberg <johannes@kyriasis.com>2014-11-05 08:51:07 +0100
commitc31da9332d2e9005baa70bd35a88826334aea0e1 (patch)
tree5367c80d1aab98d1041ae6771a001f3eca0b0eea /src
parent3e19de1edd83d44458d138d8a1b9fc8049b30c06 (diff)
downloadyawa-c31da9332d2e9005baa70bd35a88826334aea0e1.tar.xz
yawa.c: nuke atoi
Diffstat (limited to 'src')
-rw-r--r--src/yawa.c15
1 files 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;