From 12167c2d6b76dbcb224f13e82ef56c00cf3fab01 Mon Sep 17 00:00:00 2001 From: J08nY Date: Wed, 4 Oct 2017 19:30:42 +0200 Subject: Add tests for timeout option. --- src/io/cli.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'src') 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")) { -- cgit v1.2.3-70-g09d2