* [PATCH 0/2] tests/qtest: Avoid char arrays in more Arm tests
@ 2026-03-10 15:33 Peter Maydell
2026-03-10 15:33 ` [PATCH 1/2] tests/qtest/ast2700-gpio-test: Use g_strdup_printf() instead of char arrays Peter Maydell
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Peter Maydell @ 2026-03-10 15:33 UTC (permalink / raw)
To: qemu-arm, qemu-devel
Cc: Fabiano Rosas, Cédric Le Goater, Steven Lee, Troy Lee,
Jamin Lin, Andrew Jeffery, Joel Stanley
This patchset fixes a couple more -Wformat-overflow=2 warnings with
gcc 7.5.0. Same issue as this other series I just posted, but two
different files:
https://lore.kernel.org/qemu-devel/20260310151507.2973843-1-peter.maydell@linaro.org/
Since there's no dependency between the two sets of patches I sent
this out as a separate series rather than a v2 with those others
folded in.
thanks
-- PMM
Peter Maydell (2):
tests/qtest/ast2700-gpio-test: Use g_strdup_printf() instead of char
arrays
tests/qtest/aspeed_gpio-test: Use g_strdup_printf() instead of char
arrays
tests/qtest/aspeed_gpio-test.c | 4 ++--
tests/qtest/ast2700-gpio-test.c | 3 +--
2 files changed, 3 insertions(+), 4 deletions(-)
--
2.43.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 1/2] tests/qtest/ast2700-gpio-test: Use g_strdup_printf() instead of char arrays
2026-03-10 15:33 [PATCH 0/2] tests/qtest: Avoid char arrays in more Arm tests Peter Maydell
@ 2026-03-10 15:33 ` Peter Maydell
2026-03-10 17:07 ` Philippe Mathieu-Daudé
2026-03-10 15:33 ` [PATCH 2/2] tests/qtest/aspeed_gpio-test: " Peter Maydell
2026-03-10 15:50 ` [PATCH 0/2] tests/qtest: Avoid char arrays in more Arm tests Fabiano Rosas
2 siblings, 1 reply; 6+ messages in thread
From: Peter Maydell @ 2026-03-10 15:33 UTC (permalink / raw)
To: qemu-arm, qemu-devel
Cc: Fabiano Rosas, Cédric Le Goater, Steven Lee, Troy Lee,
Jamin Lin, Andrew Jeffery, Joel Stanley
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/ast2700-gpio-test.c: In function ‘test_input_pins’:
../tests/qtest/ast2700-gpio-test.c:54:36: error: ‘sprintf’ may write a terminating nul past the end of the destination [-Werror=format-overflow=]
sprintf(name, "gpio%c%d", c, i);
^
../tests/qtest/ast2700-gpio-test.c:54:13: note: ‘sprintf’ output between 7 and 17 bytes into a destination of size 16
sprintf(name, "gpio%c%d", c, i);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This 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 <farosas@suse.de>
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
tests/qtest/ast2700-gpio-test.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/tests/qtest/ast2700-gpio-test.c b/tests/qtest/ast2700-gpio-test.c
index eeae9bf11f..533feea7da 100644
--- a/tests/qtest/ast2700-gpio-test.c
+++ b/tests/qtest/ast2700-gpio-test.c
@@ -44,14 +44,13 @@ static void test_output_pins(const char *machine, const uint32_t base)
static void test_input_pins(const char *machine, const uint32_t base)
{
QTestState *s = qtest_init(machine);
- char name[16];
uint32_t offset = 0;
uint32_t value = 0;
uint32_t pin = 0;
for (char c = 'A'; c <= 'D'; c++) {
for (int i = 0; i < 8; i++) {
- sprintf(name, "gpio%c%d", c, i);
+ g_autofree const char *name = g_strdup_printf("gpio%c%d", c, i);
offset = base + (pin * 4);
/* input direction */
qtest_writel(s, offset, 0);
--
2.43.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 2/2] tests/qtest/aspeed_gpio-test: Use g_strdup_printf() instead of char arrays
2026-03-10 15:33 [PATCH 0/2] tests/qtest: Avoid char arrays in more Arm tests Peter Maydell
2026-03-10 15:33 ` [PATCH 1/2] tests/qtest/ast2700-gpio-test: Use g_strdup_printf() instead of char arrays Peter Maydell
@ 2026-03-10 15:33 ` Peter Maydell
2026-03-10 17:07 ` Philippe Mathieu-Daudé
2026-03-10 15:50 ` [PATCH 0/2] tests/qtest: Avoid char arrays in more Arm tests Fabiano Rosas
2 siblings, 1 reply; 6+ messages in thread
From: Peter Maydell @ 2026-03-10 15:33 UTC (permalink / raw)
To: qemu-arm, qemu-devel
Cc: Fabiano Rosas, Cédric Le Goater, Steven Lee, Troy Lee,
Jamin Lin, Andrew Jeffery, Joel Stanley
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/aspeed_gpio-test.c: In function ‘test_set_input_pins’:
../tests/qtest/aspeed_gpio-test.c:149:36: error: ‘sprintf’ may write a terminating nul past the end of the destination [-Werror=format-overflow=]
sprintf(name, "gpio%c%d", c, i);
^
../tests/qtest/aspeed_gpio-test.c:149:13: note: ‘sprintf’ output between 7 and 17 bytes into a destination of size 16
sprintf(name, "gpio%c%d", c, i);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This 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 <farosas@suse.de>
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
tests/qtest/aspeed_gpio-test.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/tests/qtest/aspeed_gpio-test.c b/tests/qtest/aspeed_gpio-test.c
index decbba23c8..029b3731d1 100644
--- a/tests/qtest/aspeed_gpio-test.c
+++ b/tests/qtest/aspeed_gpio-test.c
@@ -140,13 +140,13 @@ static void test_set_colocated_pins(const void *data)
static void test_set_input_pins(const void *data)
{
QTestState *s = (QTestState *)data;
- char name[16];
uint32_t value;
qtest_writel(s, AST2600_GPIO_BASE + GPIO_ABCD_DIRECTION, 0x00000000);
for (char c = 'A'; c <= 'D'; c++) {
for (int i = 0; i < 8; i++) {
- sprintf(name, "gpio%c%d", c, i);
+ g_autofree const char *name = g_strdup_printf("gpio%c%d", c, i);
+
qtest_qom_set_bool(s, "/machine/soc/gpio", name, true);
}
}
--
2.43.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 0/2] tests/qtest: Avoid char arrays in more Arm tests
2026-03-10 15:33 [PATCH 0/2] tests/qtest: Avoid char arrays in more Arm tests Peter Maydell
2026-03-10 15:33 ` [PATCH 1/2] tests/qtest/ast2700-gpio-test: Use g_strdup_printf() instead of char arrays Peter Maydell
2026-03-10 15:33 ` [PATCH 2/2] tests/qtest/aspeed_gpio-test: " Peter Maydell
@ 2026-03-10 15:50 ` Fabiano Rosas
2 siblings, 0 replies; 6+ messages in thread
From: Fabiano Rosas @ 2026-03-10 15:50 UTC (permalink / raw)
To: Peter Maydell, qemu-arm, qemu-devel
Cc: Cédric Le Goater, Steven Lee, Troy Lee, Jamin Lin,
Andrew Jeffery, Joel Stanley
Peter Maydell <peter.maydell@linaro.org> writes:
> This patchset fixes a couple more -Wformat-overflow=2 warnings with
> gcc 7.5.0. Same issue as this other series I just posted, but two
> different files:
>
> https://lore.kernel.org/qemu-devel/20260310151507.2973843-1-peter.maydell@linaro.org/
>
> Since there's no dependency between the two sets of patches I sent
> this out as a separate series rather than a v2 with those others
> folded in.
>
> thanks
> -- PMM
>
> Peter Maydell (2):
> tests/qtest/ast2700-gpio-test: Use g_strdup_printf() instead of char
> arrays
> tests/qtest/aspeed_gpio-test: Use g_strdup_printf() instead of char
> arrays
>
> tests/qtest/aspeed_gpio-test.c | 4 ++--
> tests/qtest/ast2700-gpio-test.c | 3 +--
> 2 files changed, 3 insertions(+), 4 deletions(-)
Series:
Tested-by: Fabiano Rosas <farosas@suse.de>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 2/2] tests/qtest/aspeed_gpio-test: Use g_strdup_printf() instead of char arrays
2026-03-10 15:33 ` [PATCH 2/2] tests/qtest/aspeed_gpio-test: " Peter Maydell
@ 2026-03-10 17:07 ` Philippe Mathieu-Daudé
0 siblings, 0 replies; 6+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-03-10 17:07 UTC (permalink / raw)
To: Peter Maydell, qemu-arm, qemu-devel
Cc: Fabiano Rosas, Cédric Le Goater, Steven Lee, Troy Lee,
Jamin Lin, Andrew Jeffery, Joel Stanley
On 10/3/26 16:33, Peter Maydell wrote:
> 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/aspeed_gpio-test.c: In function ‘test_set_input_pins’:
> ../tests/qtest/aspeed_gpio-test.c:149:36: error: ‘sprintf’ may write a terminating nul past the end of the destination [-Werror=format-overflow=]
> sprintf(name, "gpio%c%d", c, i);
> ^
> ../tests/qtest/aspeed_gpio-test.c:149:13: note: ‘sprintf’ output between 7 and 17 bytes into a destination of size 16
> sprintf(name, "gpio%c%d", c, i);
> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> This 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 <farosas@suse.de>
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
> tests/qtest/aspeed_gpio-test.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] tests/qtest/ast2700-gpio-test: Use g_strdup_printf() instead of char arrays
2026-03-10 15:33 ` [PATCH 1/2] tests/qtest/ast2700-gpio-test: Use g_strdup_printf() instead of char arrays Peter Maydell
@ 2026-03-10 17:07 ` Philippe Mathieu-Daudé
0 siblings, 0 replies; 6+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-03-10 17:07 UTC (permalink / raw)
To: Peter Maydell, qemu-arm, qemu-devel
Cc: Fabiano Rosas, Cédric Le Goater, Steven Lee, Troy Lee,
Jamin Lin, Andrew Jeffery, Joel Stanley
On 10/3/26 16:33, Peter Maydell wrote:
> 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/ast2700-gpio-test.c: In function ‘test_input_pins’:
> ../tests/qtest/ast2700-gpio-test.c:54:36: error: ‘sprintf’ may write a terminating nul past the end of the destination [-Werror=format-overflow=]
> sprintf(name, "gpio%c%d", c, i);
> ^
> ../tests/qtest/ast2700-gpio-test.c:54:13: note: ‘sprintf’ output between 7 and 17 bytes into a destination of size 16
> sprintf(name, "gpio%c%d", c, i);
> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> This 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 <farosas@suse.de>
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
> tests/qtest/ast2700-gpio-test.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-03-10 17:08 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-10 15:33 [PATCH 0/2] tests/qtest: Avoid char arrays in more Arm tests Peter Maydell
2026-03-10 15:33 ` [PATCH 1/2] tests/qtest/ast2700-gpio-test: Use g_strdup_printf() instead of char arrays Peter Maydell
2026-03-10 17:07 ` Philippe Mathieu-Daudé
2026-03-10 15:33 ` [PATCH 2/2] tests/qtest/aspeed_gpio-test: " Peter Maydell
2026-03-10 17:07 ` Philippe Mathieu-Daudé
2026-03-10 15:50 ` [PATCH 0/2] tests/qtest: Avoid char arrays in more Arm tests Fabiano Rosas
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox