[PATCH weston] option-parser: Require integer option string values to be base-10

Bryce Harrington bryce at osg.samsung.com
Sat Jul 9 00:52:30 UTC 2016


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 <bryce at osg.samsung.com>
---
 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 d5fee8e..33355b8 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);
-- 
1.9.1



More information about the wayland-devel mailing list