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>
This commit is contained in:
Eric Blake 2021-03-23 16:52:59 +00:00 committed by Alex Bennée
parent e5b024b930
commit 061d79097c
2 changed files with 114 additions and 7 deletions

View file

@ -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;
}