From 5556ee3afa4dc015a73bff7bcddd65d14c6a57c6 Mon Sep 17 00:00:00 2001 From: Yaroslav de la Peña Smirnov Date: Tue, 16 Sep 2025 20:38:59 +0300 Subject: cli: make long and ulong options more strict Also add unit tests for them. --- cli/cli.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'cli/cli.h') diff --git a/cli/cli.h b/cli/cli.h index 4b9a8ae..1116595 100644 --- a/cli/cli.h +++ b/cli/cli.h @@ -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; -- cgit v1.2.3