[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH] tests/cpu-policy: fix format-overflow warning by null terminating strings



From: Christopher Clark <christopher.w.clark@xxxxxxxxx>

gcc 9.1.0 reports:

| test-cpu-policy.c:64:18: error: '%.12s' directive argument is not a 
nul-terminated string [-Werror=format-overflow=]
|    64 |             fail("  Test '%.12s', expected vendor %u, got %u\n",
|       |                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| test-cpu-policy.c:20:12: note: in definition of macro 'fail'
|    20 |     printf(fmt, ##__VA_ARGS__);                 \
|       |            ^~~
| test-cpu-policy.c:64:27: note: format string is defined here
|    64 |             fail("  Test '%.12s', expected vendor %u, got %u\n",
|       |                           ^~~~~
| test-cpu-policy.c:44:7: note: referenced argument declared here
|    44 |     } tests[] = {
|       |       ^~~~~

so increase the string array size by one character for the null string
terminator and add another single char to the struct within the same
union to balance it.

Signed-off-by: Christopher Clark <christopher.clark6@xxxxxxxxxxxxxx>
---
 tools/tests/cpu-policy/test-cpu-policy.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/tools/tests/cpu-policy/test-cpu-policy.c 
b/tools/tests/cpu-policy/test-cpu-policy.c
index ca3b8dd45f..c91408a93a 100644
--- a/tools/tests/cpu-policy/test-cpu-policy.c
+++ b/tools/tests/cpu-policy/test-cpu-policy.c
@@ -35,9 +35,10 @@ static void test_vendor_identification(void)
 {
     static const struct test {
         union {
-            char ident[12];
+            char ident[13];
             struct {
                 uint32_t b, d, c;
+                char null_terminator;
             };
         };
         unsigned int vendor;
-- 
2.17.1


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.