diff options
author | Johannes Löthberg <johannes@kyriasis.com> | 2014-11-05 08:51:07 +0100 |
---|---|---|
committer | Johannes Löthberg <johannes@kyriasis.com> | 2014-11-05 08:51:07 +0100 |
commit | c31da9332d2e9005baa70bd35a88826334aea0e1 (patch) | |
tree | 5367c80d1aab98d1041ae6771a001f3eca0b0eea | |
parent | 3e19de1edd83d44458d138d8a1b9fc8049b30c06 (diff) | |
download | yawa-c31da9332d2e9005baa70bd35a88826334aea0e1.tar.xz |
yawa.c: nuke atoi
-rw-r--r-- | src/yawa.c | 15 |
1 files changed, 13 insertions, 2 deletions
@@ -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; |