[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PULL 09/21] cutils: Adjust signature of parse_uint[_full]
From: |
Markus Armbruster |
Subject: |
Re: [PULL 09/21] cutils: Adjust signature of parse_uint[_full] |
Date: |
Fri, 02 Jun 2023 08:16:38 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux) |
Sorry for being late to the party...
Eric Blake <eblake@redhat.com> writes:
> 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 and unsigned long long
> have the same width, but are not always the same type), and mark
> endptr const (this latter change only affects the rare caller of
> parse_uint). Adjust all callers in the tree.
>
> Signed-off-by: Eric Blake <eblake@redhat.com>
> Reviewed-by: Hanna Czenczek <hreitz@redhat.com>
> Message-Id: <20230522190441.64278-8-eblake@redhat.com>
[...]
> diff --git a/qapi/opts-visitor.c b/qapi/opts-visitor.c
> index 587f31baf6b..8812d23677a 100644
> --- a/qapi/opts-visitor.c
> +++ b/qapi/opts-visitor.c
> @@ -454,8 +454,8 @@ opts_type_uint64(Visitor *v, const char *name, uint64_t
> *obj, Error **errp)
> OptsVisitor *ov = to_ov(v);
> const QemuOpt *opt;
> const char *str;
> - unsigned long long val;
> - char *endptr;
> + uint64_t val;
val changes from unsigned long long, which is at least 64 bits, to
uint64_t, which is exactly 64 bits.
> + const char *endptr;
>
> if (ov->list_mode == LM_UNSIGNED_INTERVAL) {
> *obj = ov->range_next.u;
> @@ -471,17 +471,17 @@ opts_type_uint64(Visitor *v, const char *name, uint64_t
> *obj, Error **errp)
> /* we've gotten past lookup_scalar() */
> assert(ov->list_mode == LM_NONE || ov->list_mode == LM_IN_PROGRESS);
>
> - if (parse_uint(str, &val, &endptr, 0) == 0 && val <= UINT64_MAX) {
> + if (parse_uint(str, &endptr, 0, &val) == 0 && val <= UINT64_MAX) {
val <= UINT64_MAX is now useless, isn't it?
> if (*endptr == '\0') {
> *obj = val;
> processed(ov, name);
> return true;
> }
> if (*endptr == '-' && ov->list_mode == LM_IN_PROGRESS) {
> - unsigned long long val2;
> + uint64_t val2;
val2 changes from unsigned long long, which is at least 64 bits, to
uint64_t, which is exactly 64 bits.
> str = endptr + 1;
> - if (parse_uint_full(str, &val2, 0) == 0 &&
> + if (parse_uint_full(str, 0, &val2) == 0 &&
> val2 <= UINT64_MAX && val <= val2 &&
val2 <= UINT64_MAX is now useless, isn't it?
> val2 - val < OPTS_VISITOR_RANGE_MAX) {
> ov->range_next.u = val;
[...]
- [PULL 02/21] qcow2: Explicit mention of padding bytes, (continued)
- [PULL 02/21] qcow2: Explicit mention of padding bytes, Eric Blake, 2023/06/01
- [PULL 05/21] test-cutils: Test integral qemu_strto* value on failures, Eric Blake, 2023/06/01
- [PULL 01/21] iotests: Fix test 104 under NBD, Eric Blake, 2023/06/01
- [PULL 08/21] cutils: Document differences between parse_uint and qemu_strtou64, Eric Blake, 2023/06/01
- [PULL 10/21] cutils: Allow NULL endptr in parse_uint(), Eric Blake, 2023/06/01
- [PULL 11/21] test-cutils: Add coverage of qemu_strtod, Eric Blake, 2023/06/01
- [PULL 07/21] cutils: Fix wraparound parsing in qemu_strtoui, Eric Blake, 2023/06/01
- [PULL 09/21] cutils: Adjust signature of parse_uint[_full], Eric Blake, 2023/06/01
- Re: [PULL 09/21] cutils: Adjust signature of parse_uint[_full],
Markus Armbruster <=
- [PULL 18/21] cutils: Set value in all integral qemu_strto* error paths, Eric Blake, 2023/06/01
- [PULL 16/21] test-cutils: Add more coverage to qemu_strtosz, Eric Blake, 2023/06/01
- [PULL 21/21] cutils: Improve qemu_strtosz handling of fractions, Eric Blake, 2023/06/01
- [PULL 04/21] test-cutils: Use g_assert_cmpuint where appropriate, Eric Blake, 2023/06/01
- [PULL 15/21] numa: Check for qemu_strtosz_MiB error, Eric Blake, 2023/06/01
- [PULL 20/21] cutils: Improve qemu_strtod* error paths, Eric Blake, 2023/06/01
- [PULL 17/21] cutils: Set value in all qemu_strtosz* error paths, Eric Blake, 2023/06/01
- [PULL 06/21] test-cutils: Test more integer corner cases, Eric Blake, 2023/06/01