diff options
author | Yaroslav de la Peña Smirnov <yps@yaroslavps.com> | 2025-09-16 20:38:59 +0300 |
---|---|---|
committer | Yaroslav de la Peña Smirnov <yps@yaroslavps.com> | 2025-09-16 20:38:59 +0300 |
commit | 5556ee3afa4dc015a73bff7bcddd65d14c6a57c6 (patch) | |
tree | 0bad83a6eeeb621059e5506774e677953d19031c /cli/cli.h | |
parent | 9e7132fff6d905e43955803892046e0a0b1dd8fb (diff) | |
download | c-wares-5556ee3afa4dc015a73bff7bcddd65d14c6a57c6.tar.gz c-wares-5556ee3afa4dc015a73bff7bcddd65d14c6a57c6.zip |
cli: make long and ulong options more strict
Also add unit tests for them.
Diffstat (limited to 'cli/cli.h')
-rw-r--r-- | cli/cli.h | 10 |
1 files changed, 6 insertions, 4 deletions
@@ -104,8 +104,9 @@ int cli_opt_long_set(struct cli_opt *self, const char *val) struct cli_opt_long *opt = container_of(self, struct cli_opt_long, opt); errno = 0; - opt->value = strtol(val, NULL, 0); - if (errno != 0) + char *endptr; + opt->value = strtol(val, &endptr, 0); + if (errno != 0 || *endptr != '\0') return CLI_RC_BAD_ARGS; return CLI_RC_OK; @@ -133,8 +134,9 @@ int cli_opt_ulong_set(struct cli_opt *self, const char *val) struct cli_opt_ulong *opt = container_of(self, struct cli_opt_ulong, opt); errno = 0; - opt->value = strtoul(val, NULL, 0); - if (errno != 0) + char *endptr; + opt->value = strtoul(val, &endptr, 0); + if (errno != 0 || *endptr != '\0') return CLI_RC_BAD_ARGS; return CLI_RC_OK; |