qemu-block
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v2 07/19] cutils: Adjust signature of parse_uint[_full]


From: Hanna Czenczek
Subject: Re: [PATCH v2 07/19] cutils: Adjust signature of parse_uint[_full]
Date: Fri, 19 May 2023 16:51:55 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.10.0

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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]