From: Markus Armbruster <armbru@redhat.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PULL 04/24] test-cutils: Clean up qemu_strtoul() result checks
Date: Thu, 23 Feb 2017 20:53:42 +0100 [thread overview]
Message-ID: <1487879642-16139-5-git-send-email-armbru@redhat.com> (raw)
In-Reply-To: <1487879642-16139-1-git-send-email-armbru@redhat.com>
Use unsigned comparisons to check the result of qemu_strtoul() and
strtoull().
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <1487708048-2131-5-git-send-email-armbru@redhat.com>
---
tests/test-cutils.c | 60 ++++++++++++++++++++++++++---------------------------
1 file changed, 30 insertions(+), 30 deletions(-)
diff --git a/tests/test-cutils.c b/tests/test-cutils.c
index 71681dc..749aaa9 100644
--- a/tests/test-cutils.c
+++ b/tests/test-cutils.c
@@ -523,7 +523,7 @@ static void test_qemu_strtoul_correct(void)
err = qemu_strtoul(str, &endptr, 0, &res);
g_assert_cmpint(err, ==, 0);
- g_assert_cmpint(res, ==, 12345);
+ g_assert_cmpuint(res, ==, 12345);
g_assert(endptr == str + 5);
}
@@ -593,7 +593,7 @@ static void test_qemu_strtoul_trailing(void)
err = qemu_strtoul(str, &endptr, 0, &res);
g_assert_cmpint(err, ==, 0);
- g_assert_cmpint(res, ==, 123);
+ g_assert_cmpuint(res, ==, 123);
g_assert(endptr == str + 3);
}
@@ -608,7 +608,7 @@ static void test_qemu_strtoul_octal(void)
err = qemu_strtoul(str, &endptr, 8, &res);
g_assert_cmpint(err, ==, 0);
- g_assert_cmpint(res, ==, 0123);
+ g_assert_cmpuint(res, ==, 0123);
g_assert(endptr == str + strlen(str));
res = 999;
@@ -616,7 +616,7 @@ static void test_qemu_strtoul_octal(void)
err = qemu_strtoul(str, &endptr, 0, &res);
g_assert_cmpint(err, ==, 0);
- g_assert_cmpint(res, ==, 0123);
+ g_assert_cmpuint(res, ==, 0123);
g_assert(endptr == str + strlen(str));
}
@@ -631,7 +631,7 @@ static void test_qemu_strtoul_decimal(void)
err = qemu_strtoul(str, &endptr, 10, &res);
g_assert_cmpint(err, ==, 0);
- g_assert_cmpint(res, ==, 123);
+ g_assert_cmpuint(res, ==, 123);
g_assert(endptr == str + strlen(str));
str = "123";
@@ -640,7 +640,7 @@ static void test_qemu_strtoul_decimal(void)
err = qemu_strtoul(str, &endptr, 0, &res);
g_assert_cmpint(err, ==, 0);
- g_assert_cmpint(res, ==, 123);
+ g_assert_cmpuint(res, ==, 123);
g_assert(endptr == str + strlen(str));
}
@@ -655,7 +655,7 @@ static void test_qemu_strtoul_hex(void)
err = qemu_strtoul(str, &endptr, 16, &res);
g_assert_cmpint(err, ==, 0);
- g_assert_cmpint(res, ==, 0x123);
+ g_assert_cmphex(res, ==, 0x123);
g_assert(endptr == str + strlen(str));
str = "0x123";
@@ -664,7 +664,7 @@ static void test_qemu_strtoul_hex(void)
err = qemu_strtoul(str, &endptr, 0, &res);
g_assert_cmpint(err, ==, 0);
- g_assert_cmpint(res, ==, 0x123);
+ g_assert_cmphex(res, ==, 0x123);
g_assert(endptr == str + strlen(str));
}
@@ -679,7 +679,7 @@ static void test_qemu_strtoul_max(void)
err = qemu_strtoul(str, &endptr, 0, &res);
g_assert_cmpint(err, ==, 0);
- g_assert_cmpint(res, ==, ULONG_MAX);
+ g_assert_cmphex(res, ==, ULONG_MAX);
g_assert(endptr == str + strlen(str));
g_free(str);
}
@@ -695,7 +695,7 @@ static void test_qemu_strtoul_overflow(void)
err = qemu_strtoul(str, &endptr, 0, &res);
g_assert_cmpint(err, ==, -ERANGE);
- g_assert_cmpint(res, ==, ULONG_MAX);
+ g_assert_cmphex(res, ==, ULONG_MAX);
g_assert(endptr == str + strlen(str));
}
@@ -710,7 +710,7 @@ static void test_qemu_strtoul_underflow(void)
err = qemu_strtoul(str, &endptr, 0, &res);
g_assert_cmpint(err, ==, -ERANGE);
- g_assert_cmpint(res, ==, -1ul);
+ g_assert_cmpuint(res, ==, -1ul);
g_assert(endptr == str + strlen(str));
}
@@ -725,7 +725,7 @@ static void test_qemu_strtoul_negative(void)
err = qemu_strtoul(str, &endptr, 0, &res);
g_assert_cmpint(err, ==, 0);
- g_assert_cmpint(res, ==, -321ul);
+ g_assert_cmpuint(res, ==, -321ul);
g_assert(endptr == str + strlen(str));
}
@@ -738,7 +738,7 @@ static void test_qemu_strtoul_full_correct(void)
err = qemu_strtoul(str, NULL, 0, &res);
g_assert_cmpint(err, ==, 0);
- g_assert_cmpint(res, ==, 123);
+ g_assert_cmpuint(res, ==, 123);
}
static void test_qemu_strtoul_full_null(void)
@@ -769,7 +769,7 @@ static void test_qemu_strtoul_full_negative(void)
err = qemu_strtoul(str, NULL, 0, &res);
g_assert_cmpint(err, ==, 0);
- g_assert_cmpint(res, ==, -321ul);
+ g_assert_cmpuint(res, ==, -321ul);
}
static void test_qemu_strtoul_full_trailing(void)
@@ -792,7 +792,7 @@ static void test_qemu_strtoul_full_max(void)
err = qemu_strtoul(str, NULL, 0, &res);
g_assert_cmpint(err, ==, 0);
- g_assert_cmpint(res, ==, ULONG_MAX);
+ g_assert_cmphex(res, ==, ULONG_MAX);
g_free(str);
}
@@ -1094,7 +1094,7 @@ static void test_qemu_strtoull_correct(void)
err = qemu_strtoull(str, &endptr, 0, &res);
g_assert_cmpint(err, ==, 0);
- g_assert_cmpint(res, ==, 12345);
+ g_assert_cmpuint(res, ==, 12345);
g_assert(endptr == str + 5);
}
@@ -1164,7 +1164,7 @@ static void test_qemu_strtoull_trailing(void)
err = qemu_strtoull(str, &endptr, 0, &res);
g_assert_cmpint(err, ==, 0);
- g_assert_cmpint(res, ==, 123);
+ g_assert_cmpuint(res, ==, 123);
g_assert(endptr == str + 3);
}
@@ -1179,7 +1179,7 @@ static void test_qemu_strtoull_octal(void)
err = qemu_strtoull(str, &endptr, 8, &res);
g_assert_cmpint(err, ==, 0);
- g_assert_cmpint(res, ==, 0123);
+ g_assert_cmpuint(res, ==, 0123);
g_assert(endptr == str + strlen(str));
endptr = &f;
@@ -1187,7 +1187,7 @@ static void test_qemu_strtoull_octal(void)
err = qemu_strtoull(str, &endptr, 0, &res);
g_assert_cmpint(err, ==, 0);
- g_assert_cmpint(res, ==, 0123);
+ g_assert_cmpuint(res, ==, 0123);
g_assert(endptr == str + strlen(str));
}
@@ -1202,7 +1202,7 @@ static void test_qemu_strtoull_decimal(void)
err = qemu_strtoull(str, &endptr, 10, &res);
g_assert_cmpint(err, ==, 0);
- g_assert_cmpint(res, ==, 123);
+ g_assert_cmpuint(res, ==, 123);
g_assert(endptr == str + strlen(str));
str = "123";
@@ -1211,7 +1211,7 @@ static void test_qemu_strtoull_decimal(void)
err = qemu_strtoull(str, &endptr, 0, &res);
g_assert_cmpint(err, ==, 0);
- g_assert_cmpint(res, ==, 123);
+ g_assert_cmpuint(res, ==, 123);
g_assert(endptr == str + strlen(str));
}
@@ -1226,7 +1226,7 @@ static void test_qemu_strtoull_hex(void)
err = qemu_strtoull(str, &endptr, 16, &res);
g_assert_cmpint(err, ==, 0);
- g_assert_cmpint(res, ==, 0x123);
+ g_assert_cmphex(res, ==, 0x123);
g_assert(endptr == str + strlen(str));
str = "0x123";
@@ -1235,7 +1235,7 @@ static void test_qemu_strtoull_hex(void)
err = qemu_strtoull(str, &endptr, 0, &res);
g_assert_cmpint(err, ==, 0);
- g_assert_cmpint(res, ==, 0x123);
+ g_assert_cmphex(res, ==, 0x123);
g_assert(endptr == str + strlen(str));
}
@@ -1250,7 +1250,7 @@ static void test_qemu_strtoull_max(void)
err = qemu_strtoull(str, &endptr, 0, &res);
g_assert_cmpint(err, ==, 0);
- g_assert_cmpint(res, ==, ULLONG_MAX);
+ g_assert_cmphex(res, ==, ULLONG_MAX);
g_assert(endptr == str + strlen(str));
g_free(str);
}
@@ -1266,7 +1266,7 @@ static void test_qemu_strtoull_overflow(void)
err = qemu_strtoull(str, &endptr, 0, &res);
g_assert_cmpint(err, ==, -ERANGE);
- g_assert_cmpint(res, ==, ULLONG_MAX);
+ g_assert_cmphex(res, ==, ULLONG_MAX);
g_assert(endptr == str + strlen(str));
}
@@ -1281,7 +1281,7 @@ static void test_qemu_strtoull_underflow(void)
err = qemu_strtoull(str, &endptr, 0, &res);
g_assert_cmpint(err, ==, -ERANGE);
- g_assert_cmpint(res, ==, -1);
+ g_assert_cmphex(res, ==, -1ull);
g_assert(endptr == str + strlen(str));
}
@@ -1296,7 +1296,7 @@ static void test_qemu_strtoull_negative(void)
err = qemu_strtoull(str, &endptr, 0, &res);
g_assert_cmpint(err, ==, 0);
- g_assert_cmpint(res, ==, -321);
+ g_assert_cmpuint(res, ==, -321ull);
g_assert(endptr == str + strlen(str));
}
@@ -1309,7 +1309,7 @@ static void test_qemu_strtoull_full_correct(void)
err = qemu_strtoull(str, NULL, 0, &res);
g_assert_cmpint(err, ==, 0);
- g_assert_cmpint(res, ==, 18446744073709551614LLU);
+ g_assert_cmpuint(res, ==, 18446744073709551614ull);
}
static void test_qemu_strtoull_full_null(void)
@@ -1342,7 +1342,7 @@ static void test_qemu_strtoull_full_negative(void)
err = qemu_strtoull(str, NULL, 0, &res);
g_assert_cmpint(err, ==, 0);
- g_assert_cmpint(res, ==, 18446744073709551295LLU);
+ g_assert_cmpuint(res, ==, -321ull);
}
static void test_qemu_strtoull_full_trailing(void)
@@ -1365,7 +1365,7 @@ static void test_qemu_strtoull_full_max(void)
err = qemu_strtoull(str, NULL, 0, &res);
g_assert_cmpint(err, ==, 0);
- g_assert_cmpint(res, ==, ULLONG_MAX);
+ g_assert_cmphex(res, ==, ULLONG_MAX);
g_free(str);
}
--
2.7.4
next prev parent reply other threads:[~2017-02-23 19:54 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-02-23 19:53 [Qemu-devel] [PULL 00/24] option cutils: Fix and clean up number conversions Markus Armbruster
2017-02-23 19:53 ` [Qemu-devel] [PULL 01/24] test-qemu-opts: Cover qemu_opts_parse() Markus Armbruster
2017-02-23 19:53 ` [Qemu-devel] [PULL 02/24] option: Assert value string isn't null Markus Armbruster
2017-02-23 19:53 ` [Qemu-devel] [PULL 03/24] test-cutils: Add missing qemu_strtol()... endptr checks Markus Armbruster
2017-02-23 19:53 ` Markus Armbruster [this message]
2017-02-23 19:53 ` [Qemu-devel] [PULL 05/24] util/cutils: Rewrite documentation of qemu_strtol() & friends Markus Armbruster
2017-02-23 19:53 ` [Qemu-devel] [PULL 06/24] util/cutils: Rename qemu_strtoll(), qemu_strtoull() Markus Armbruster
2017-02-23 19:53 ` [Qemu-devel] [PULL 07/24] util/cutils: Clean up variable names around qemu_strtol() Markus Armbruster
2017-02-23 19:53 ` [Qemu-devel] [PULL 08/24] util/cutils: Clean up control flow around qemu_strtol() a bit Markus Armbruster
2017-02-23 19:53 ` [Qemu-devel] [PULL 09/24] option: Fix to reject invalid and overflowing numbers Markus Armbruster
2017-02-23 19:53 ` [Qemu-devel] [PULL 10/24] test-cutils: Add missing qemu_strtosz()... endptr checks Markus Armbruster
2017-02-23 19:53 ` [Qemu-devel] [PULL 11/24] test-cutils: Cover qemu_strtosz() invalid input Markus Armbruster
2017-02-23 19:53 ` [Qemu-devel] [PULL 12/24] test-cutils: Cover qemu_strtosz() with trailing crap Markus Armbruster
2017-02-23 19:53 ` [Qemu-devel] [PULL 13/24] test-cutils: Cover qemu_strtosz() around range limits Markus Armbruster
2017-02-23 19:53 ` [Qemu-devel] [PULL 14/24] util/cutils: New qemu_strtosz_metric() Markus Armbruster
2017-02-23 19:53 ` [Qemu-devel] [PULL 15/24] util/cutils: Rename qemu_strtosz() to qemu_strtosz_MiB() Markus Armbruster
2017-02-23 19:53 ` [Qemu-devel] [PULL 16/24] util/cutils: New qemu_strtosz() Markus Armbruster
2017-02-23 19:53 ` [Qemu-devel] [PULL 17/24] util/cutils: Drop QEMU_STRTOSZ_DEFSUFFIX_* macros Markus Armbruster
2017-02-23 19:53 ` [Qemu-devel] [PULL 18/24] test-cutils: Use qemu_strtosz() more often Markus Armbruster
2017-02-23 19:53 ` [Qemu-devel] [PULL 19/24] test-cutils: Drop suffix from test_qemu_strtosz_simple() Markus Armbruster
2017-02-23 19:53 ` [Qemu-devel] [PULL 20/24] qemu-img: Wrap cvtnum() around qemu_strtosz() Markus Armbruster
2017-02-23 19:53 ` [Qemu-devel] [PULL 21/24] util/cutils: Let qemu_strtosz*() optionally reject trailing crap Markus Armbruster
2017-02-23 19:54 ` [Qemu-devel] [PULL 22/24] util/cutils: Return qemu_strtosz*() error and value separately Markus Armbruster
2017-02-23 19:54 ` [Qemu-devel] [PULL 23/24] util/cutils: Change qemu_strtosz*() from int64_t to uint64_t Markus Armbruster
2017-02-23 19:54 ` [Qemu-devel] [PULL 24/24] option: Fix checking of sizes for overflow and trailing crap Markus Armbruster
2017-02-23 20:37 ` [Qemu-devel] [PULL 00/24] option cutils: Fix and clean up number conversions no-reply
2017-02-25 16:37 ` Peter Maydell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1487879642-16139-5-git-send-email-armbru@redhat.com \
--to=armbru@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).