util: if errno is nonzero, exit early from safe_atoi

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
(cherry picked from commit 13428f5d82)
This commit is contained in:
Peter Hutterer 2016-11-24 10:48:39 +10:00
parent 59d1ed9466
commit 690dd44121

View file

@ -28,6 +28,7 @@
#include "config.h"
#include <assert.h>
#include <errno.h>
#include <limits.h>
#include <math.h>
#include <stdarg.h>
@ -410,7 +411,10 @@ safe_atoi(const char *str, int *val)
char *endptr;
long v;
errno = 0;
v = strtol(str, &endptr, 10);
if (errno > 0)
return false;
if (str == endptr)
return false;
if (*str != '\0' && *endptr != '\0')