diff options
author | Roland Lutz <rlutz@hedmen.org> | 2017-06-07 20:11:43 +0200 |
---|---|---|
committer | Roland Lutz <rlutz@hedmen.org> | 2017-06-08 21:01:45 +0200 |
commit | 90381332e2063618431fa42cf5028870c5453cb4 (patch) | |
tree | d8bc2628dc8fa8f3da5925357eb863fb96cd81c9 /iceprog | |
parent | dbdc65b65b6862af3b7afdb4ef6c3d2a153541e5 (diff) | |
download | icestorm-90381332e2063618431fa42cf5028870c5453cb4.tar.gz icestorm-90381332e2063618431fa42cf5028870c5453cb4.tar.bz2 icestorm-90381332e2063618431fa42cf5028870c5453cb4.zip |
iceprog: Check for invalid offset/size arguments
Diffstat (limited to 'iceprog')
-rw-r--r-- | iceprog/iceprog.c | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/iceprog/iceprog.c b/iceprog/iceprog.c index 8f93427..7886811 100644 --- a/iceprog/iceprog.c +++ b/iceprog/iceprog.c @@ -385,13 +385,21 @@ int main(int argc, char **argv) case 'R': read_mode = true; read_size = strtol(optarg, &endptr, 0); - if (!strcmp(endptr, "k")) read_size *= 1024; - if (!strcmp(endptr, "M")) read_size *= 1024 * 1024; + if (*endptr == '\0') /* ok */; + else if (!strcmp(endptr, "k")) read_size *= 1024; + else if (!strcmp(endptr, "M")) read_size *= 1024 * 1024; + else + errx(EXIT_FAILURE, + "`%s' is not a valid size", optarg); break; case 'o': rw_offset = strtol(optarg, &endptr, 0); - if (!strcmp(endptr, "k")) rw_offset *= 1024; - if (!strcmp(endptr, "M")) rw_offset *= 1024 * 1024; + if (*endptr == '\0') /* ok */; + else if (!strcmp(endptr, "k")) rw_offset *= 1024; + else if (!strcmp(endptr, "M")) rw_offset *= 1024 * 1024; + else + errx(EXIT_FAILURE, + "`%s' is not a valid offset", optarg); break; case 'c': check_mode = true; |