diff options
| author | J08nY | 2017-10-04 19:30:42 +0200 |
|---|---|---|
| committer | J08nY | 2017-10-04 19:30:42 +0200 |
| commit | 12167c2d6b76dbcb224f13e82ef56c00cf3fab01 (patch) | |
| tree | 5b7ba87092e65f4138eecbf4491f7aa61d622516 /src/io/cli.c | |
| parent | 531c26c732ca8d01cd95c88c70bed6038bc8cba8 (diff) | |
| download | ecgen-12167c2d6b76dbcb224f13e82ef56c00cf3fab01.tar.gz ecgen-12167c2d6b76dbcb224f13e82ef56c00cf3fab01.tar.zst ecgen-12167c2d6b76dbcb224f13e82ef56c00cf3fab01.zip | |
Diffstat (limited to 'src/io/cli.c')
| -rw-r--r-- | src/io/cli.c | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/src/io/cli.c b/src/io/cli.c index 74e6cc7..0a707de 100644 --- a/src/io/cli.c +++ b/src/io/cli.c @@ -73,9 +73,13 @@ struct argp_option cli_options[] = { }; // clang-format on -static unsigned long cli_parse_memory(const char *str) { +static unsigned long cli_parse_memory(const char *str, + struct argp_state *state) { char *suffix = NULL; unsigned long read = strtoul(str, &suffix, 10); + if (suffix == str) { + argp_failure(state, 1, 0, "Wrong memory value."); + } if (suffix) { if (*suffix == 'k' || *suffix == 'K') { read *= 1000; @@ -88,9 +92,12 @@ static unsigned long cli_parse_memory(const char *str) { return read; } -static unsigned long cli_parse_time(const char *str) { +static unsigned long cli_parse_time(const char *str, struct argp_state *state) { char *suffix = NULL; unsigned long read = strtoul(str, &suffix, 10); + if (suffix == str) { + argp_failure(state, 1, 0, "Wrong time value."); + } if (suffix) { if (*suffix == 'm' || *suffix == 'M') { read *= 60; @@ -111,13 +118,13 @@ error_t cli_parse(int key, char *arg, struct argp_state *state) { cfg->datadir = arg; break; case OPT_MEMORY: - cfg->memory = cli_parse_memory(arg); + cfg->memory = cli_parse_memory(arg, state); break; case OPT_TSTACK: - cfg->thread_memory = cli_parse_memory(arg); + cfg->thread_memory = cli_parse_memory(arg, state); break; case OPT_TIMEOUT: - cfg->timeout = cli_parse_time(arg); + cfg->timeout = cli_parse_time(arg, state); break; case OPT_THREADS: if (!strcmp(arg, "auto") || !strcmp(arg, "AUTO")) { |
