aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorEric Blake <eblake@redhat.com>2021-03-23 16:53:00 +0000
committerAlex Bennée <alex.bennee@linaro.org>2021-03-24 14:25:41 +0000
commit6162f7dafef51b44c5700ac3f82ff682faafe6c2 (patch)
treee2800a51427d5ce25c336344a2db229cb55b956b /tests
parent061d79097c080722e359db7c0d9cddc006cfb14d (diff)
utils: Work around mingw strto*l bug with 0x
Mingw recognizes that "0x" has value 0 without setting errno, but fails to advance endptr to the trailing garbage 'x'. This in turn showed up in our recent testsuite additions for qemu_strtosz (commit 1657ba44b4 utils: Enhance testsuite for do_strtosz()); adjust our remaining tests to show that we now work around this windows bug. This patch intentionally fails check-syntax for use of strtol. Signed-off-by: Eric Blake <eblake@redhat.com> Signed-off-by: Alex Bennée <alex.bennee@linaro.org> Reviewed-by: Thomas Huth <thuth@redhat.com> Message-Id: <20210317143325.2165821-3-eblake@redhat.com> Message-Id: <20210323165308.15244-15-alex.bennee@linaro.org>
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/test-cutils.c54
1 files changed, 54 insertions, 0 deletions
diff --git a/tests/unit/test-cutils.c b/tests/unit/test-cutils.c
index 5908de4fd0..98671f1ac3 100644
--- a/tests/unit/test-cutils.c
+++ b/tests/unit/test-cutils.c
@@ -378,6 +378,15 @@ static void test_qemu_strtoi_hex(void)
g_assert_cmpint(err, ==, 0);
g_assert_cmpint(res, ==, 0x123);
g_assert(endptr == str + strlen(str));
+
+ str = "0x";
+ res = 999;
+ endptr = &f;
+ err = qemu_strtoi(str, &endptr, 16, &res);
+
+ g_assert_cmpint(err, ==, 0);
+ g_assert_cmpint(res, ==, 0);
+ g_assert(endptr == str + 1);
}
static void test_qemu_strtoi_max(void)
@@ -669,6 +678,15 @@ static void test_qemu_strtoui_hex(void)
g_assert_cmpint(err, ==, 0);
g_assert_cmphex(res, ==, 0x123);
g_assert(endptr == str + strlen(str));
+
+ str = "0x";
+ res = 999;
+ endptr = &f;
+ err = qemu_strtoui(str, &endptr, 16, &res);
+
+ g_assert_cmpint(err, ==, 0);
+ g_assert_cmphex(res, ==, 0);
+ g_assert(endptr == str + 1);
}
static void test_qemu_strtoui_max(void)
@@ -955,6 +973,15 @@ static void test_qemu_strtol_hex(void)
g_assert_cmpint(err, ==, 0);
g_assert_cmpint(res, ==, 0x123);
g_assert(endptr == str + strlen(str));
+
+ str = "0x";
+ res = 999;
+ endptr = &f;
+ err = qemu_strtol(str, &endptr, 16, &res);
+
+ g_assert_cmpint(err, ==, 0);
+ g_assert_cmpint(res, ==, 0);
+ g_assert(endptr == str + 1);
}
static void test_qemu_strtol_max(void)
@@ -1244,6 +1271,15 @@ static void test_qemu_strtoul_hex(void)
g_assert_cmpint(err, ==, 0);
g_assert_cmphex(res, ==, 0x123);
g_assert(endptr == str + strlen(str));
+
+ str = "0x";
+ res = 999;
+ endptr = &f;
+ err = qemu_strtoul(str, &endptr, 16, &res);
+
+ g_assert_cmpint(err, ==, 0);
+ g_assert_cmphex(res, ==, 0);
+ g_assert(endptr == str + 1);
}
static void test_qemu_strtoul_max(void)
@@ -1528,6 +1564,15 @@ static void test_qemu_strtoi64_hex(void)
g_assert_cmpint(err, ==, 0);
g_assert_cmpint(res, ==, 0x123);
g_assert(endptr == str + strlen(str));
+
+ str = "0x";
+ endptr = &f;
+ res = 999;
+ err = qemu_strtoi64(str, &endptr, 16, &res);
+
+ g_assert_cmpint(err, ==, 0);
+ g_assert_cmpint(res, ==, 0);
+ g_assert(endptr == str + 1);
}
static void test_qemu_strtoi64_max(void)
@@ -1815,6 +1860,15 @@ static void test_qemu_strtou64_hex(void)
g_assert_cmpint(err, ==, 0);
g_assert_cmphex(res, ==, 0x123);
g_assert(endptr == str + strlen(str));
+
+ str = "0x";
+ endptr = &f;
+ res = 999;
+ err = qemu_strtou64(str, &endptr, 16, &res);
+
+ g_assert_cmpint(err, ==, 0);
+ g_assert_cmphex(res, ==, 0);
+ g_assert(endptr == str + 1);
}
static void test_qemu_strtou64_max(void)