mirror of
https://github.com/utmapp/qemu.git
synced 2026-12-01 22:23:23 -10:00
tests/qtest/arm-cpu-features: Use g_strdup_printf() instead of char arrays
Older versions of gcc with -Wformat-overflow=2 don't like the usage of fixed size char arrays in this test; gcc 7.5.0 (SUSE Linux) says: ../tests/qtest/arm-cpu-features.c: In function ‘test_query_cpu_model_expansion_kvm’: ../tests/qtest/arm-cpu-features.c:578:35: error: ‘%u’ directive writing between 1 and 10 bytes into a region of size 5 [-Werror=format-overflow=] These can't actually happen because of the limited size of the values being substituted in. However rather than require readers to check whether the arrays really have been declared large enough, we prefer to use g_strdup_printf() for this kind of string work. Reported-by: Fabiano Rosas <[email protected]> Signed-off-by: Peter Maydell <[email protected]> Tested-by: Fabiano Rosas <[email protected]> Reviewed-by: Cédric Le Goater <[email protected]> Reviewed-by: Philippe Mathieu-Daudé <[email protected]> Message-id: [email protected]
This commit is contained in:
1 parent
632d7bc0ec
commit
62272f9f88
1 file changed
+15
-9
@@ -519,7 +519,6 @@ static void test_query_cpu_model_expansion_kvm(const void *data)
|
||||
bool kvm_supports_pmu;
|
||||
bool kvm_supports_steal_time;
|
||||
bool kvm_supports_sve;
|
||||
char max_name[8], name[8];
|
||||
uint32_t max_vq, vq;
|
||||
uint64_t vls;
|
||||
QDict *resp;
|
||||
@@ -573,9 +572,12 @@ static void test_query_cpu_model_expansion_kvm(const void *data)
|
||||
}
|
||||
|
||||
if (kvm_supports_sve) {
|
||||
g_autofree const char *max_name = NULL;
|
||||
g_autofree const char *name = NULL;
|
||||
|
||||
g_assert(vls != 0);
|
||||
max_vq = 64 - __builtin_clzll(vls);
|
||||
sprintf(max_name, "sve%u", max_vq * 128);
|
||||
max_name = g_strdup_printf("sve%u", max_vq * 128);
|
||||
|
||||
/* Enabling a supported length is of course fine. */
|
||||
assert_sve_vls(qts, "host", vls, "{ %s: true }", max_name);
|
||||
@@ -583,6 +585,9 @@ static void test_query_cpu_model_expansion_kvm(const void *data)
|
||||
/* Get the next supported length smaller than max-vq. */
|
||||
vq = 64 - __builtin_clzll(vls & ~BIT_ULL(max_vq - 1));
|
||||
if (vq) {
|
||||
g_autofree const char *name2 =
|
||||
g_strdup_printf("sve%u", vq * 128);
|
||||
|
||||
/*
|
||||
* We have at least one length smaller than max-vq,
|
||||
* so we can disable max-vq.
|
||||
@@ -595,11 +600,10 @@ static void test_query_cpu_model_expansion_kvm(const void *data)
|
||||
* unless all larger, supported vector lengths are also
|
||||
* disabled.
|
||||
*/
|
||||
sprintf(name, "sve%u", vq * 128);
|
||||
error = g_strdup_printf("cannot disable %s", name);
|
||||
error = g_strdup_printf("cannot disable %s", name2);
|
||||
assert_error(qts, "host", error,
|
||||
"{ %s: true, %s: false }",
|
||||
max_name, name);
|
||||
max_name, name2);
|
||||
g_free(error);
|
||||
}
|
||||
|
||||
@@ -608,7 +612,7 @@ static void test_query_cpu_model_expansion_kvm(const void *data)
|
||||
* we need at least one vector length enabled.
|
||||
*/
|
||||
vq = __builtin_ffsll(vls);
|
||||
sprintf(name, "sve%u", vq * 128);
|
||||
name = g_strdup_printf(name, "sve%u", vq * 128);
|
||||
error = g_strdup_printf("cannot disable %s", name);
|
||||
assert_error(qts, "host", error, "{ %s: false }", name);
|
||||
g_free(error);
|
||||
@@ -620,9 +624,11 @@ static void test_query_cpu_model_expansion_kvm(const void *data)
|
||||
}
|
||||
}
|
||||
if (vq <= SVE_MAX_VQ) {
|
||||
sprintf(name, "sve%u", vq * 128);
|
||||
error = g_strdup_printf("cannot enable %s", name);
|
||||
assert_error(qts, "host", error, "{ %s: true }", name);
|
||||
g_autofree const char *name2 =
|
||||
g_strdup_printf("sve%u", vq * 128);
|
||||
|
||||
error = g_strdup_printf("cannot enable %s", name2);
|
||||
assert_error(qts, "host", error, "{ %s: true }", name2);
|
||||
g_free(error);
|
||||
}
|
||||
} else {
|
||||
|
||||
Reference in new issue
Block a user