Switch to use safe_strtoint instead of strtol

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:
Bryce Harrington
2016-08-03 17:40:52 -07:00
parent 82b9f2baec
commit 25a2bdd814
7 changed files with 21 additions and 34 deletions
+2 -5
View File
@@ -41,6 +41,7 @@
#include <wayland-util.h>
#include "config-parser.h"
#include "helpers.h"
#include "string-helpers.h"
struct weston_config_entry {
char *key;
@@ -161,7 +162,6 @@ weston_config_section_get_int(struct weston_config_section *section,
int32_t *value, int32_t default_value)
{
struct weston_config_entry *entry;
char *end;
entry = config_section_get_entry(section, key);
if (entry == NULL) {
@@ -170,11 +170,8 @@ weston_config_section_get_int(struct weston_config_section *section,
return -1;
}
errno = 0;
*value = strtol(entry->value, &end, 10);
if (errno != 0 || end == entry->value || *end != '\0') {
if (!safe_strtoint(entry->value, value)) {
*value = default_value;
errno = EINVAL;
return -1;
}
+2 -3
View File
@@ -33,6 +33,7 @@
#include <errno.h>
#include "config-parser.h"
#include "string-helpers.h"
static int
handle_option(const struct weston_option *option, char *value)
@@ -41,9 +42,7 @@ handle_option(const struct weston_option *option, char *value)
switch (option->type) {
case WESTON_OPTION_INTEGER:
errno = 0;
* (int32_t *) option->data = strtol(value, &p, 10);
if (errno != 0 || p == value || *p != '\0')
if (!safe_strtoint(value, option->data))
return 0;
return 1;
case WESTON_OPTION_UNSIGNED_INTEGER: