From 061d79097c080722e359db7c0d9cddc006cfb14d Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Tue, 23 Mar 2021 16:52:59 +0000 Subject: utils: Tighter tests for qemu_strtosz MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Our tests were not validating the return value in all cases, nor was it guaranteeing our documented claim that 'res' is unchanged on error. For that matter, it wasn't as thorough as the existing tests for qemu_strtoi() and friends for proving that endptr and res are sanely set. Enhancing the test found one case where we violated our documentation: namely, when failing with EINVAL when endptr is NULL, we shouldn't modify res. Signed-off-by: Eric Blake Signed-off-by: Alex Bennée Reviewed-by: Thomas Huth Message-Id: <20210317143325.2165821-2-eblake@redhat.com> Message-Id: <20210323165308.15244-14-alex.bennee@linaro.org> --- util/cutils.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'util/cutils.c') diff --git a/util/cutils.c b/util/cutils.c index c442882..b425ed6 100644 --- a/util/cutils.c +++ b/util/cutils.c @@ -362,7 +362,6 @@ static int do_strtosz(const char *nptr, const char **end, } } - *result = val; retval = 0; out: @@ -371,6 +370,9 @@ out: } else if (*endptr) { retval = -EINVAL; } + if (retval == 0) { + *result = val; + } return retval; } -- cgit v1.1