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
+3 -6
View File
@@ -58,6 +58,7 @@
#include "presentation-time-server-protocol.h"
#include "shared/helpers.h"
#include "shared/os-compatibility.h"
#include "shared/string-helpers.h"
#include "shared/timespec-util.h"
#include "git-version.h"
#include "version.h"
@@ -4622,15 +4623,11 @@ compositor_bind(struct wl_client *client,
WL_EXPORT int
weston_environment_get_fd(const char *env)
{
char *e, *end;
char *e;
int fd, flags;
e = getenv(env);
if (!e)
return -1;
errno = 0;
fd = strtol(e, &end, 10);
if (errno != 0 || end == e || *end != '\0')
if (!e || !safe_strtoint(e, &fd))
return -1;
flags = fcntl(fd, F_GETFD);
+5 -6
View File
@@ -44,13 +44,14 @@
#include <string.h>
#include <errno.h>
#include "shared/string-helpers.h"
static long backlight_get(struct backlight *backlight, char *node)
{
char buffer[100];
char *path;
char *end;
int fd;
long value, ret;
int fd, value;
long ret;
if (asprintf(&path, "%s/%s", backlight->path, node) < 0)
return -ENOMEM;
@@ -66,9 +67,7 @@ static long backlight_get(struct backlight *backlight, char *node)
goto out;
}
errno = 0;
value = strtol(buffer, &end, 10);
if (errno != 0 || end == buffer || *end != '\0') {
if (!safe_strtoint(buffer, &value)) {
ret = -1;
goto out;
}