diff options
author | David Hildenbrand <david@redhat.com> | 2018-11-21 17:44:14 +0100 |
---|---|---|
committer | Markus Armbruster <armbru@redhat.com> | 2018-12-13 19:10:06 +0100 |
commit | af02f4c5179675ad4e26b17ba26694a8fcde17fa (patch) | |
tree | 7b316a4e89c962284f479f604f4b2515b4cc4f97 /tests/test-cutils.c | |
parent | ca28f5481607e5c59481e70e429f5dd23662cb69 (diff) |
cutils: Fix qemu_strtosz() & friends to reject non-finite sizes
qemu_strtosz() & friends reject NaNs, but happily accept infinities.
They shouldn't. Fix that.
The fix makes use of qemu_strtod_finite(). To avoid ugly casts,
change the @end parameter of qemu_strtosz() & friends from char **
to const char **.
Also, add two test cases, testing that "inf" and "NaN" are properly
rejected. While at it, also fixup the function documentation.
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: David Hildenbrand <david@redhat.com>
Message-Id: <20181121164421.20780-3-david@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Diffstat (limited to 'tests/test-cutils.c')
-rw-r--r-- | tests/test-cutils.c | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/tests/test-cutils.c b/tests/test-cutils.c index d85c3e0f6d..1aa8351520 100644 --- a/tests/test-cutils.c +++ b/tests/test-cutils.c @@ -1950,7 +1950,7 @@ static void test_qemu_strtou64_full_max(void) static void test_qemu_strtosz_simple(void) { const char *str; - char *endptr = NULL; + const char *endptr; int err; uint64_t res = 0xbaadf00d; @@ -2017,7 +2017,7 @@ static void test_qemu_strtosz_units(void) const char *p = "1P"; const char *e = "1E"; int err; - char *endptr = NULL; + const char *endptr; uint64_t res = 0xbaadf00d; /* default is M */ @@ -2066,7 +2066,7 @@ static void test_qemu_strtosz_float(void) { const char *str = "12.345M"; int err; - char *endptr = NULL; + const char *endptr; uint64_t res = 0xbaadf00d; err = qemu_strtosz(str, &endptr, &res); @@ -2078,7 +2078,7 @@ static void test_qemu_strtosz_float(void) static void test_qemu_strtosz_invalid(void) { const char *str; - char *endptr = NULL; + const char *endptr; int err; uint64_t res = 0xbaadf00d; @@ -2096,12 +2096,22 @@ static void test_qemu_strtosz_invalid(void) err = qemu_strtosz(str, &endptr, &res); g_assert_cmpint(err, ==, -EINVAL); g_assert(endptr == str); + + str = "inf"; + err = qemu_strtosz(str, &endptr, &res); + g_assert_cmpint(err, ==, -EINVAL); + g_assert(endptr == str); + + str = "NaN"; + err = qemu_strtosz(str, &endptr, &res); + g_assert_cmpint(err, ==, -EINVAL); + g_assert(endptr == str); } static void test_qemu_strtosz_trailing(void) { const char *str; - char *endptr = NULL; + const char *endptr; int err; uint64_t res = 0xbaadf00d; @@ -2126,7 +2136,7 @@ static void test_qemu_strtosz_trailing(void) static void test_qemu_strtosz_erange(void) { const char *str; - char *endptr = NULL; + const char *endptr; int err; uint64_t res = 0xbaadf00d; @@ -2160,7 +2170,7 @@ static void test_qemu_strtosz_metric(void) { const char *str = "12345k"; int err; - char *endptr = NULL; + const char *endptr; uint64_t res = 0xbaadf00d; err = qemu_strtosz_metric(str, &endptr, &res); |