Require base-10 for strtol() calls

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.

This change is an expansion of f6051cbab8
to cover the remaining strtol() calls in Weston, where the routine is
being used to read fds and pids - which are always expressed in base-10.
It also changes the calls in config-parser, used by
weston_config_section_get_int(), which in turn is being used to read
scales, sizes, times, rates, and delays; these are all expressed in
base-10 numbers only.

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, it may make it possible to
factor out the common code in the future.

Signed-off-by: Bryce Harrington <bryce@osg.samsung.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
Bryce Harrington 2016-07-12 16:51:27 -07:00
parent 1dbdc0bd8a
commit 375759e636
4 changed files with 4 additions and 4 deletions

View File

@ -1684,7 +1684,7 @@ int main(int argc, char *argv[])
server_socket = getenv("WAYLAND_SERVER_SOCKET");
if (server_socket) {
weston_log("Running with single client\n");
fd = strtol(server_socket, &end, 0);
fd = strtol(server_socket, &end, 10);
if (*end != '\0')
fd = -1;
} else {

View File

@ -4617,7 +4617,7 @@ weston_environment_get_fd(const char *env)
e = getenv(env);
if (!e)
return -1;
fd = strtol(e, &end, 0);
fd = strtol(e, &end, 10);
if (*end != '\0')
return -1;

View File

@ -170,7 +170,7 @@ weston_config_section_get_int(struct weston_config_section *section,
}
errno = 0;
*value = strtol(entry->value, &end, 0);
*value = strtol(entry->value, &end, 10);
if (errno != 0 || end == entry->value || *end != '\0') {
*value = default_value;
errno = EINVAL;

View File

@ -164,7 +164,7 @@ create_lockfile(int display, char *lockfile, size_t lsize)
return -1;
}
other = strtol(pid, &end, 0);
other = strtol(pid, &end, 10);
if (end != pid + 10) {
weston_log("can't parse lock file %s\n",
lockfile);