[GEDI] [PATCH v2 07/19] cutils: Adjust signature of parse_uint[_full]
Hanna Czenczek
hreitz at redhat.com
Fri May 19 14:47:30 UTC 2023
On 12.05.23 04:10, Eric Blake wrote:
> It's already confusing that we have two very similar functions for
> wrapping the parse of a 64-bit unsigned value, differing mainly on
> whether they permit leading '-'. Adjust the signature of parse_uint()
> and parse_uint_full() to be like all of qemu_strto*(): put the result
> parameter last, use the same types (uint64_t is not always the same as
> unsigned long long, and mark endptr const (only latter affects the
> rare caller of parse_uint). Adjust all callers in the tree.
>
> Signed-off-by: Eric Blake <eblake at redhat.com>
> ---
> include/qemu/cutils.h | 5 +-
> audio/audio_legacy.c | 4 +-
> block/gluster.c | 4 +-
> block/nfs.c | 4 +-
> blockdev.c | 4 +-
> contrib/ivshmem-server/main.c | 4 +-
> qapi/opts-visitor.c | 10 +--
> tests/unit/test-cutils.c | 113 +++++++++++++++-------------------
> ui/vnc.c | 4 +-
> util/cutils.c | 13 ++--
> util/guest-random.c | 4 +-
> util/qemu-sockets.c | 10 +--
> 12 files changed, 82 insertions(+), 97 deletions(-)
[...]
> diff --git a/tests/unit/test-cutils.c b/tests/unit/test-cutils.c
> index 08989d1d3ac..0c7d07b3297 100644
> --- a/tests/unit/test-cutils.c
> +++ b/tests/unit/test-cutils.c
[...]
> @@ -186,32 +176,31 @@ static void test_parse_uint_max(void)
>
> static void test_parse_uint_overflow(void)
> {
> - unsigned long long i;
> - char f = 'X';
> - char *endptr;
> + uint64_t i;
> + const char *endptr = "somewhere";
The initialization here is technically not necessary because it’s reset
above the parse_uint() call below.
Anyway:
Reviewed-by: Hanna Czenczek <hreitz at redhat.com>
> const char *str;
> int r;
>
> i = 999;
> - endptr = &f;
> + endptr = "somewhere";
> str = "99999999999999999999999999999999999999";
> - r = parse_uint(str, &i, &endptr, 0);
> + r = parse_uint(str, &endptr, 0, &i);
> g_assert_cmpint(r, ==, -ERANGE);
> g_assert_cmpuint(i, ==, ULLONG_MAX);
> g_assert_true(endptr == str + strlen(str));
More information about the integration
mailing list