build/printf: fix incorrect format specifiers
authorRoger Pau Monné <roger.pau@citrix.com>
Fri, 17 Feb 2017 15:09:38 +0000 (16:09 +0100)
committerJan Beulich <jbeulich@suse.com>
Fri, 17 Feb 2017 15:09:38 +0000 (16:09 +0100)
The following incorrect format specifiers and incorrect number of parameters
passed to printf like functions are reported by clang:

mce.c:601:18: error: data argument not used by format string [-Werror,-Wformat-extra-args]
                 smp_processor_id());
                 ^

xenpm.c:102:23: error: data argument not used by format string [-Werror,-Wformat-extra-args]
                what, argv[argc > 1]);
                      ^

libxl_internal.c:25:69: error: data argument not used by format string
      [-Werror,-Wformat-extra-args]
    libxl__log(ctx, XTL_CRITICAL, ENOMEM, 0,0, func, INVALID_DOMID, L);
                                                                    ^
libxl_internal.c:24:17: note: expanded from macro 'L'
          func, (unsigned long)nmemb, (unsigned long)size
                ^
libxl_internal.c:26:21: error: data argument not used by format string
      [-Werror,-Wformat-extra-args]
    fprintf(stderr, L);
                    ^
libxl_internal.c:24:17: note: expanded from macro 'L'
          func, (unsigned long)nmemb, (unsigned long)size
                ^

This patch contains the fixes for them and enables -Wformat for clang.

Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
Acked-by: Wei Liu <wei.liu2@citrix.com>
Config.mk
tools/libxl/libxl_internal.c
tools/misc/xenpm.c
xen/arch/x86/cpu/mcheck/mce.c

index 3a1d960bdc4241152326f2dc4eac395fc735adbd..7d08d16957ac987f81ff1e3effa410e3a9224104 100644 (file)
--- a/Config.mk
+++ b/Config.mk
@@ -213,9 +213,8 @@ CFLAGS += -std=gnu99
 CFLAGS += -Wall -Wstrict-prototypes
 
 # Clang complains about macros that expand to 'if ( ( foo == bar ) ) ...'
-# and is over-zealous with the printf format lint
 # and is a bit too fierce about unused return values
-CFLAGS-$(clang) += -Wno-parentheses -Wno-format -Wno-unused-value
+CFLAGS-$(clang) += -Wno-parentheses -Wno-unused-value
 
 $(call cc-option-add,HOSTCFLAGS,HOSTCC,-Wdeclaration-after-statement)
 $(call cc-option-add,CFLAGS,CC,-Wdeclaration-after-statement)
index d288215089ea9e0bede15ce386d899fb8dc43074..f492dae5ff7055078a20f7a25a7e06063cd35bbd 100644 (file)
 void libxl__alloc_failed(libxl_ctx *ctx, const char *func,
                          size_t nmemb, size_t size) {
 #define M "libxl: FATAL ERROR: memory allocation failure"
-#define L (size ? M " (%s, %lu x %lu)\n" : M " (%s)\n"), \
-          func, (unsigned long)nmemb, (unsigned long)size
-    libxl__log(ctx, XTL_CRITICAL, ENOMEM, 0,0, func, INVALID_DOMID, L);
-    fprintf(stderr, L);
+#define M_SIZE M " (%s, %lu x %lu)\n"
+#define M_NSIZE M " (%s)\n"
+    if (size) {
+       libxl__log(ctx, XTL_CRITICAL, ENOMEM, 0, 0, func, INVALID_DOMID,
+                  M_SIZE, func, (unsigned long)nmemb, (unsigned long)size);
+       fprintf(stderr, M_SIZE, func, (unsigned long)nmemb,
+               (unsigned long)size);
+    } else {
+       libxl__log(ctx, XTL_CRITICAL, ENOMEM, 0, 0, func, INVALID_DOMID,
+                  M_NSIZE, func);
+       fprintf(stderr, M_NSIZE, func);
+
+    }
+
     fflush(stderr);
     _exit(-1);
+#undef M_NSIZE
+#undef M_SIZE
 #undef M
-#undef L
 }
 
 void libxl__ptr_add(libxl__gc *gc, void *ptr)
index a2edee5e01c7612e91fcde0bc18f720e0bd00938..ded40b9083980e4123832e63c79a005cec73aae4 100644 (file)
@@ -93,13 +93,16 @@ static void parse_cpuid(const char *arg, int *cpuid)
 static void parse_cpuid_and_int(int argc, char *argv[],
                                 int *cpuid, int *val, const char *what)
 {
-    if ( argc > 1 )
-        parse_cpuid(argv[0], cpuid);
+    if ( argc == 0 )
+    {
+         fprintf(stderr, "Missing %s\n", what);
+         exit(EINVAL);
+    }
 
-    if ( argc == 0 || sscanf(argv[argc > 1], "%d", val) != 1 )
+    parse_cpuid(argv[0], cpuid);
+    if ( sscanf(argv[1], "%d", val) != 1 )
     {
-        fprintf(stderr, argc ? "Invalid %s '%s'\n" : "Missing %s\n",
-                what, argv[argc > 1]);
+        fprintf(stderr, "Invalid %s '%s'\n", what, argv[1]);
         exit(EINVAL);
     }
 }
index b01504f575be74cede7acb047dcf1ae2b78e024d..9fb56ae87e414a4b1bbdc26eeb1e079793778911 100644 (file)
@@ -591,9 +591,8 @@ int show_mca_info(int inited, struct cpuinfo_x86 *c)
             [mcheck_intel] = "Intel"
         };
 
-        snprintf(prefix, ARRAY_SIZE(prefix),
-                 g_type != mcheck_unset ? XENLOG_WARNING "CPU%i: "
-                 : XENLOG_INFO,
+        snprintf(prefix, ARRAY_SIZE(prefix), "%sCPU%u: ",
+                 g_type != mcheck_unset ? XENLOG_WARNING : XENLOG_INFO,
                  smp_processor_id());
         BUG_ON(inited >= ARRAY_SIZE(type_str));
         switch (inited) {