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 <bryce@osg.samsung.com>
This commit is contained in:
Bryce Harrington 2016-07-08 17:44:10 -07:00
parent cbc053781e
commit f6051cbab8

View File

@ -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);