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>
diff --git a/shared/config-parser.c b/shared/config-parser.c
index 1edfd60..d773cc9 100644
--- a/shared/config-parser.c
+++ b/shared/config-parser.c
@@ -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 @@
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 @@
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;
}
diff --git a/shared/option-parser.c b/shared/option-parser.c
index fb4a342..eee7546 100644
--- a/shared/option-parser.c
+++ b/shared/option-parser.c
@@ -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 @@
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: