mirror of
https://gitlab.freedesktop.org/wayland/weston
synced 2024-07-22 11:14:21 +00:00
option-parser: Improve error checking for strtol call
Make the error checking consistent with other strtol() calls. Note that since strtol(nptr, &endptr) sets endptr == nptr if there were no digits, this catches the case where the string was blank, so there's no need to test *value != '\0'. Signed-off-by: Bryce Harrington <bryce@osg.samsung.com> Reviewed-by: Eric Engestrom <eric.engestrom@imgtec.com> Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
parent
139fcabe7c
commit
d9779e3ff1
|
@ -30,6 +30,7 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
#include "config-parser.h"
|
#include "config-parser.h"
|
||||||
|
|
||||||
|
@ -40,11 +41,17 @@ handle_option(const struct weston_option *option, char *value)
|
||||||
|
|
||||||
switch (option->type) {
|
switch (option->type) {
|
||||||
case WESTON_OPTION_INTEGER:
|
case WESTON_OPTION_INTEGER:
|
||||||
|
errno = 0;
|
||||||
* (int32_t *) option->data = strtol(value, &p, 10);
|
* (int32_t *) option->data = strtol(value, &p, 10);
|
||||||
return *value && !*p;
|
if (errno != 0 || p == value || *p != '\0')
|
||||||
|
return 0;
|
||||||
|
return 1;
|
||||||
case WESTON_OPTION_UNSIGNED_INTEGER:
|
case WESTON_OPTION_UNSIGNED_INTEGER:
|
||||||
|
errno = 0;
|
||||||
* (uint32_t *) option->data = strtoul(value, &p, 10);
|
* (uint32_t *) option->data = strtoul(value, &p, 10);
|
||||||
return *value && !*p;
|
if (errno != 0 || p == value || *p != '\0')
|
||||||
|
return 0;
|
||||||
|
return 1;
|
||||||
case WESTON_OPTION_STRING:
|
case WESTON_OPTION_STRING:
|
||||||
* (char **) option->data = strdup(value);
|
* (char **) option->data = strdup(value);
|
||||||
return 1;
|
return 1;
|
||||||
|
|
Loading…
Reference in a new issue