From c975cf44748be9cba358f90c84174ed7e0fa403a Mon Sep 17 00:00:00 2001 From: ejurgensen Date: Fri, 27 Jan 2017 10:59:34 +0100 Subject: [PATCH] [misc] Set output of safe_xxx to 0 also in error cases (for safety) --- src/misc.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/misc.c b/src/misc.c index 101c6472..94d9f509 100644 --- a/src/misc.c +++ b/src/misc.c @@ -48,6 +48,8 @@ safe_atoi32(const char *str, int32_t *val) char *end; long intval; + *val = 0; + errno = 0; intval = strtol(str, &end, 10); @@ -84,6 +86,8 @@ safe_atou32(const char *str, uint32_t *val) char *end; unsigned long intval; + *val = 0; + errno = 0; intval = strtoul(str, &end, 10); @@ -120,6 +124,8 @@ safe_hextou32(const char *str, uint32_t *val) char *end; unsigned long intval; + *val = 0; + /* A hex shall begin with 0x */ if (strncmp(str, "0x", 2) != 0) return safe_atou32(str, val); @@ -160,6 +166,8 @@ safe_atoi64(const char *str, int64_t *val) char *end; long long intval; + *val = 0; + errno = 0; intval = strtoll(str, &end, 10); @@ -196,6 +204,8 @@ safe_atou64(const char *str, uint64_t *val) char *end; unsigned long long intval; + *val = 0; + errno = 0; intval = strtoull(str, &end, 10); @@ -232,6 +242,8 @@ safe_hextou64(const char *str, uint64_t *val) char *end; unsigned long long intval; + *val = 0; + errno = 0; intval = strtoull(str, &end, 16);