From f0e6bbea0a06645616c387358ec1b422fcb1d933 Mon Sep 17 00:00:00 2001 From: Wojciech Malikowski Date: Tue, 29 Jan 2019 03:37:58 -0500 Subject: [PATCH] util/string: additional errno check after strtol() Without this check valgrind complains that we are using uninitialized variable. Change-Id: I5cb73d10e167004f6e4df9e3621ec3b35ec2448d Signed-off-by: Wojciech Malikowski Reviewed-on: https://review.gerrithub.io/c/442519 Reviewed-by: Darek Stojaczyk Reviewed-by: Jim Harris Tested-by: SPDK CI Jenkins --- lib/util/string.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/util/string.c b/lib/util/string.c index cc22a9638..c3b6a3f16 100644 --- a/lib/util/string.c +++ b/lib/util/string.c @@ -425,7 +425,7 @@ spdk_strtol(const char *nptr, int base) val = strtol(nptr, &endptr, base); - if (*endptr != '\0') { + if (!errno && *endptr != '\0') { /* Non integer character was found. */ return -EINVAL; } else if (errno == ERANGE && (val == LONG_MAX || val == LONG_MIN)) { @@ -456,7 +456,7 @@ spdk_strtoll(const char *nptr, int base) val = strtoll(nptr, &endptr, base); - if (*endptr != '\0') { + if (!errno && *endptr != '\0') { /* Non integer character was found. */ return -EINVAL; } else if (errno == ERANGE && (val == LLONG_MAX || val == LLONG_MIN)) {