From patchwork Tue Feb 14 12:30:55 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Roger_Pau_Monn=C3=A9?= X-Patchwork-Id: 9571833 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id C581860578 for ; Tue, 14 Feb 2017 12:33:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B464828365 for ; Tue, 14 Feb 2017 12:33:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A8F13283A6; Tue, 14 Feb 2017 12:33:31 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 3435728365 for ; Tue, 14 Feb 2017 12:33:30 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cdcGD-0008FS-IB; Tue, 14 Feb 2017 12:31:09 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cdcGC-0008F1-JD for xen-devel@lists.xenproject.org; Tue, 14 Feb 2017 12:31:08 +0000 Received: from [85.158.139.211] by server-11.bemta-5.messagelabs.com id 1B/80-01711-B88F2A85; Tue, 14 Feb 2017 12:31:07 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprNIsWRWlGSWpSXmKPExsXitHSDvW73j0U RBp2b2Cy+b5nM5MDocfjDFZYAxijWzLyk/IoE1oyZKzIK7ulWNE0Wa2DsVO5i5OSQEPCXaHtx mA3EZhPQkbg4dyeQzcEhIqAicXuvQRcjFwezwDNGib3PFjKC1AgLuEosODkLrJ5FQFVi3+7DY HFeAUuJy1cusUHM1JPYdeQ3K4jNKWAlMXHBIzBbCKjm0f+HzBD1ghInZz5hAbGZBTQlWrf/Zo ew5SWat85mhqhXlOif94BtAiPfLCQts5C0zELSsoCReRWjRnFqUVlqka6RiV5SUWZ6RkluYma OrqGBqV5uanFxYnpqTmJSsV5yfu4mRmCg1TMwMO5gvDnZ7xCjJAeTkihv7KaFEUJ8SfkplRmJ xRnxRaU5qcWHGGU4OJQkeP2/L4oQEixKTU+tSMvMAYY8TFqCg0dJhPfMN6A0b3FBYm5xZjpE6 hSjopQ4ryRInwBIIqM0D64NFmeXGGWlhHkZGRgYhHgKUotyM0tQ5V8xinMwKgnzioNM4cnMK4 Gb/gpoMRPQYta4hSCLSxIRUlINjH097Dfnz7LWviz3unI2S0Tr9LNLHj7bq8a+S3WxkxTPwyN OS2fsuP8udsf2GIFvudsNbkx+xvmu4s+6nNmbfzgKu8zeJhX7es7k87yt6+qZurIWrzj3Sn+/ isHnvs13dsResOQ9xXtn0+V9T5JdjZ1/qwv5G6wMDL5x4KT47asn7iZe/bLiRUSsEktxRqKhF nNRcSIAuZUahq4CAAA= X-Env-Sender: prvs=211416eb8=roger.pau@citrix.com X-Msg-Ref: server-6.tower-206.messagelabs.com!1487075465!84628136!1 X-Originating-IP: [66.165.176.63] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni42MyA9PiAzMDYwNDg=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 9.2.3; banners=-,-,- X-VirusChecked: Checked Received: (qmail 61451 invoked from network); 14 Feb 2017 12:31:06 -0000 Received: from smtp02.citrix.com (HELO SMTP02.CITRIX.COM) (66.165.176.63) by server-6.tower-206.messagelabs.com with RC4-SHA encrypted SMTP; 14 Feb 2017 12:31:06 -0000 X-IronPort-AV: E=Sophos;i="5.35,161,1484006400"; d="scan'208";a="415705119" From: Roger Pau Monne To: Date: Tue, 14 Feb 2017 12:30:55 +0000 Message-ID: <20170214123057.92544-3-roger.pau@citrix.com> X-Mailer: git-send-email 2.10.1 (Apple Git-78) In-Reply-To: <20170214123057.92544-1-roger.pau@citrix.com> References: <20170214123057.92544-1-roger.pau@citrix.com> MIME-Version: 1.0 Cc: Wei Liu , Andrew Cooper , Christoph Egger , Ian Jackson , Jan Beulich , Roger Pau Monne Subject: [Xen-devel] [PATCH v4 2/4] build/printf: fix incorrect format specifiers X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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é Acked-by: Andrew Cooper Acked-by: Wei Liu --- NB: FWIW, there's a way to disable extra arguments checks (-Wno-format-extra-args), that would prevent us from having to apply some of the changes here. However, given that there are not that many occurrences, I would rather leave the full checks of Wformat enabled. NB2: this has only been tested with a FreeBSD clang build (3.8.0), and only against the components that build on FreeBSD (ie: no qemu-trad, and certainly no blktap). --- Cc: Ian Jackson Cc: Wei Liu Cc: Christoph Egger Cc: Jan Beulich Cc: Andrew Cooper --- Changes since v2: - Remove the printf related comment near the -Wno-format. Changes since v1: - Change the format string for MCE to avoid duplicating CPU%i. - Remove the grant-ref format specifier change, it's already taken care in patch #1. --- Config.mk | 3 +-- tools/libxl/libxl_internal.c | 21 ++++++++++++++++----- tools/misc/xenpm.c | 13 ++++++++----- xen/arch/x86/cpu/mcheck/mce.c | 5 ++--- 4 files changed, 27 insertions(+), 15 deletions(-) diff --git a/Config.mk b/Config.mk index 3a1d960..7d08d16 100644 --- 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) diff --git a/tools/libxl/libxl_internal.c b/tools/libxl/libxl_internal.c index d288215..f492dae 100644 --- a/tools/libxl/libxl_internal.c +++ b/tools/libxl/libxl_internal.c @@ -20,14 +20,25 @@ 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) diff --git a/tools/misc/xenpm.c b/tools/misc/xenpm.c index a2edee5..ded40b9 100644 --- a/tools/misc/xenpm.c +++ b/tools/misc/xenpm.c @@ -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); } } diff --git a/xen/arch/x86/cpu/mcheck/mce.c b/xen/arch/x86/cpu/mcheck/mce.c index 2695b0c..6616026 100644 --- a/xen/arch/x86/cpu/mcheck/mce.c +++ b/xen/arch/x86/cpu/mcheck/mce.c @@ -595,9 +595,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) {