[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 3/5] tests/unit: fix a -Wformat-truncation warning
From: |
Peter Maydell |
Subject: |
[PULL 3/5] tests/unit: fix a -Wformat-truncation warning |
Date: |
Fri, 12 Aug 2022 12:45:25 +0100 |
From: Marc-André Lureau <marcandre.lureau@redhat.com>
../tests/test-qobject-input-visitor.c: In function ‘test_visitor_in_list’:
../tests/test-qobject-input-visitor.c:454:49: warning: ‘%d’ directive output
may be truncated writing between 1 and 10 bytes into a region of size 6
[-Wformat-truncation=]
454 | snprintf(string, sizeof(string), "string%d", i);
| ^~
../tests/test-qobject-input-visitor.c:454:42: note: directive argument in the
range [0, 2147483606]
454 | snprintf(string, sizeof(string), "string%d", i);
| ^~~~~~~~~~
../tests/test-qobject-input-visitor.c:454:9: note: ‘snprintf’ output between 8
and 17 bytes into a destination of size 12
454 | snprintf(string, sizeof(string), "string%d", i);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Rather than trying to be clever, since this is called 3 times during
tests, let's simply use g_strdup_printf().
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Message-id: 20220810121513.1356081-1-marcandre.lureau@redhat.com
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
[PMM: fixed commit message typos]
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
tests/unit/test-qobject-input-visitor.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/tests/unit/test-qobject-input-visitor.c
b/tests/unit/test-qobject-input-visitor.c
index 14329dabcfe..5f614afdbf1 100644
--- a/tests/unit/test-qobject-input-visitor.c
+++ b/tests/unit/test-qobject-input-visitor.c
@@ -447,9 +447,8 @@ static void test_visitor_in_list(TestInputVisitorData *data,
g_assert(head != NULL);
for (i = 0, item = head; item; item = item->next, i++) {
- char string[12];
+ g_autofree char *string = g_strdup_printf("string%d", i);
- snprintf(string, sizeof(string), "string%d", i);
g_assert_cmpstr(item->value->string, ==, string);
g_assert_cmpint(item->value->integer, ==, 42 + i);
}
--
2.25.1
- [PULL 0/5] target-arm queue, Peter Maydell, 2022/08/12
- [PULL 3/5] tests/unit: fix a -Wformat-truncation warning,
Peter Maydell <=
- [PULL 2/5] Fix some typos in documentation (most of them found by codespell), Peter Maydell, 2022/08/12
- [PULL 4/5] hw/arm/virt-acpi-build: Present the GICR structure properly for GICv4, Peter Maydell, 2022/08/12
- [PULL 5/5] cutils: Add missing dyld(3) include on macOS, Peter Maydell, 2022/08/12
- [PULL 1/5] target/arm: Don't report Statistical Profiling Extension in ID registers, Peter Maydell, 2022/08/12
- Re: [PULL 0/5] target-arm queue, Richard Henderson, 2022/08/12