x86/cpu-policy: work around bogus warning in test harness
diff mbox series

Message ID 81569b49-5121-89b2-1002-0a9b14b9d1dd@suse.com
State New, archived
Headers show
Series
  • x86/cpu-policy: work around bogus warning in test harness
Related show

Commit Message

Jan Beulich Sept. 5, 2019, 6:14 a.m. UTC
Despite %.12s properly limiting the number of characters read from
ident[], gcc 9 (at least up to 9.2.0) warns about the strings not
being nul-terminated:

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[] = {
      |       ^~~~~

The issue was reported against gcc in their bugzilla (bug 91667).

Re-order array entries, oddly enough suppressing the warning.

Reported-by: Christopher Clark <christopher.w.clark@gmail.com>
Signed-off-by: Jan Beulich <jbeulich@suse.com>

Comments

Andrew Cooper Sept. 5, 2019, 7:22 a.m. UTC | #1
On 05/09/2019 07:14, Jan Beulich wrote:
> Despite %.12s properly limiting the number of characters read from
> ident[], gcc 9 (at least up to 9.2.0) warns about the strings not
> being nul-terminated:
>
> 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[] = {
>       |       ^~~~~
>
> The issue was reported against gcc in their bugzilla (bug 91667).
>
> Re-order array entries, oddly enough suppressing the warning.
>
> Reported-by: Christopher Clark <christopher.w.clark@gmail.com>

Reported-by: Dario Faggioli <dfaggioli@suse.com> as well.

> Signed-off-by: Jan Beulich <jbeulich@suse.com>

I see you managed to create a smaller synthetic example.  That is just
bizzare, but oh well.

Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>

>
> --- a/tools/tests/cpu-policy/test-cpu-policy.c
> +++ b/tools/tests/cpu-policy/test-cpu-policy.c
> @@ -42,15 +42,16 @@ static void test_vendor_identification(v
>          };
>          unsigned int vendor;
>      } tests[] = {
> +        /* The 1st entry should remain here to work around gcc bug 91667. */
> +        { { ""             }, X86_VENDOR_UNKNOWN },
> +        { { "            " }, X86_VENDOR_UNKNOWN },
> +        { { "xxxxxxxxxxxx" }, X86_VENDOR_UNKNOWN },
> +
>          { { "GenuineIntel" }, X86_VENDOR_INTEL },
>          { { "AuthenticAMD" }, X86_VENDOR_AMD },
>          { { "CentaurHauls" }, X86_VENDOR_CENTAUR },
>          { { "  Shanghai  " }, X86_VENDOR_SHANGHAI },
>          { { "HygonGenuine" }, X86_VENDOR_HYGON },
> -
> -        { { ""             }, X86_VENDOR_UNKNOWN },
> -        { { "            " }, X86_VENDOR_UNKNOWN },
> -        { { "xxxxxxxxxxxx" }, X86_VENDOR_UNKNOWN },
>      };
>  
>      printf("Testing CPU vendor identification:\n");

Patch
diff mbox series

--- a/tools/tests/cpu-policy/test-cpu-policy.c
+++ b/tools/tests/cpu-policy/test-cpu-policy.c
@@ -42,15 +42,16 @@  static void test_vendor_identification(v
         };
         unsigned int vendor;
     } tests[] = {
+        /* The 1st entry should remain here to work around gcc bug 91667. */
+        { { ""             }, X86_VENDOR_UNKNOWN },
+        { { "            " }, X86_VENDOR_UNKNOWN },
+        { { "xxxxxxxxxxxx" }, X86_VENDOR_UNKNOWN },
+
         { { "GenuineIntel" }, X86_VENDOR_INTEL },
         { { "AuthenticAMD" }, X86_VENDOR_AMD },
         { { "CentaurHauls" }, X86_VENDOR_CENTAUR },
         { { "  Shanghai  " }, X86_VENDOR_SHANGHAI },
         { { "HygonGenuine" }, X86_VENDOR_HYGON },
-
-        { { ""             }, X86_VENDOR_UNKNOWN },
-        { { "            " }, X86_VENDOR_UNKNOWN },
-        { { "xxxxxxxxxxxx" }, X86_VENDOR_UNKNOWN },
     };
 
     printf("Testing CPU vendor identification:\n");