aboutsummaryrefslogtreecommitdiff
path: root/util/cutils.c
diff options
context:
space:
mode:
authorEric Blake <eblake@redhat.com>2021-03-23 16:52:59 +0000
committerAlex Bennée <alex.bennee@linaro.org>2021-03-24 14:25:37 +0000
commit061d79097c080722e359db7c0d9cddc006cfb14d (patch)
treea174b564fb61388d09884f529c7f3db9befcc9ee /util/cutils.c
parente5b024b93047db9126b382cbad49b70eea912dd6 (diff)
downloadqemu-061d79097c080722e359db7c0d9cddc006cfb14d.zip
qemu-061d79097c080722e359db7c0d9cddc006cfb14d.tar.gz
qemu-061d79097c080722e359db7c0d9cddc006cfb14d.tar.bz2
utils: Tighter tests for qemu_strtosz
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 <eblake@redhat.com> Signed-off-by: Alex Bennée <alex.bennee@linaro.org> Reviewed-by: Thomas Huth <thuth@redhat.com> Message-Id: <20210317143325.2165821-2-eblake@redhat.com> Message-Id: <20210323165308.15244-14-alex.bennee@linaro.org>
Diffstat (limited to 'util/cutils.c')
-rw-r--r--util/cutils.c4
1 files changed, 3 insertions, 1 deletions
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;
}