From f6051cbab84c0e577473b67f0585c0f329eb80fe Mon Sep 17 00:00:00 2001 From: Bryce Harrington Date: Fri, 8 Jul 2016 17:44:10 -0700 Subject: [PATCH] option-parser: Require integer option string values to be base-10 The third arg to strtol() specifies the base to assume for the number. When 0 is passed, as is currently done in option-parser.c, hexadecimal and octal numbers are permitted and automatically detected and converted. In weston and the weston clients and tests using option-parser.c, the options are all things that can be expected to be specified in base 10: widths, heights, counts, scales, font sizes, ports, ttys, connectors, etc. The subsurfaces client uses two modes, limited to values 0 and 1 only. The zuc testsuite has a --random parameter for specifying a seed, which is the only option where using hexadecimal or octal numbers might conceivably happen. The benefit of limiting this to base-10 is to eliminate surprises when parsing numbers from the command line. Also, by making the code consistent with other usages of strtol/strtoul, it may make it possible to factor out the common code in the future. Signed-off-by: Bryce Harrington --- shared/option-parser.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/shared/option-parser.c b/shared/option-parser.c index d5fee8ec..33355b8b 100644 --- a/shared/option-parser.c +++ b/shared/option-parser.c @@ -40,10 +40,10 @@ handle_option(const struct weston_option *option, char *value) switch (option->type) { case WESTON_OPTION_INTEGER: - * (int32_t *) option->data = strtol(value, &p, 0); + * (int32_t *) option->data = strtol(value, &p, 10); return *value && !*p; case WESTON_OPTION_UNSIGNED_INTEGER: - * (uint32_t *) option->data = strtoul(value, &p, 0); + * (uint32_t *) option->data = strtoul(value, &p, 10); return *value && !*p; case WESTON_OPTION_STRING: * (char **) option->data = strdup(value);