From patchwork Wed Apr 3 15:35:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Dooks X-Patchwork-Id: 10884023 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7E75818E8 for ; Wed, 3 Apr 2019 15:35:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 656A728770 for ; Wed, 3 Apr 2019 15:35:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 598C328787; Wed, 3 Apr 2019 15:35:57 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F180C287F4 for ; Wed, 3 Apr 2019 15:35:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726269AbfDCPf4 (ORCPT ); Wed, 3 Apr 2019 11:35:56 -0400 Received: from imap1.codethink.co.uk ([176.9.8.82]:51740 "EHLO imap1.codethink.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726264AbfDCPf4 (ORCPT ); Wed, 3 Apr 2019 11:35:56 -0400 Received: from [167.98.27.226] (helo=rainbowdash.codethink.co.uk) by imap1.codethink.co.uk with esmtpsa (Exim 4.84_2 #1 (Debian)) id 1hBhve-0005VQ-Qg; Wed, 03 Apr 2019 16:35:54 +0100 Received: from ben by rainbowdash.codethink.co.uk with local (Exim 4.92) (envelope-from ) id 1hBhve-00067h-1b; Wed, 03 Apr 2019 16:35:54 +0100 From: Ben Dooks To: linux-sparse@vger.kernel.org Cc: Ben Dooks Subject: [PATCH 4/6] add -Wformat Date: Wed, 3 Apr 2019 16:35:50 +0100 Message-Id: <20190403153552.23461-5-ben.dooks@codethink.co.uk> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190403153552.23461-1-ben.dooks@codethink.co.uk> References: <20190403153552.23461-1-ben.dooks@codethink.co.uk> MIME-Version: 1.0 Sender: linux-sparse-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add option to enable/disable format checking (and default it to on) Signed-off-by: Ben Dooks --- Changes since v1: - Default -Wformat off --- evaluate.c | 2 +- lib.c | 2 ++ lib.h | 1 + sparse.1 | 9 +++++++++ 4 files changed, 13 insertions(+), 1 deletion(-) diff --git a/evaluate.c b/evaluate.c index d6e8415..a21bc3f 100644 --- a/evaluate.c +++ b/evaluate.c @@ -2743,7 +2743,7 @@ static int evaluate_arguments(struct symbol *fn, struct expression_list *head) /* do this first, otherwise the arugment info may get lost or changed * later on in the evaluation loop. */ - if (fn->ctype.printf_va_start) + if (Wformat && fn->ctype.printf_va_start) evaluate_format_printf(fn, head); PREPARE_PTR_LIST(argument_types, argtype); diff --git a/lib.c b/lib.c index 83e6a1e..b3bb2e6 100644 --- a/lib.c +++ b/lib.c @@ -269,6 +269,7 @@ int Wimplicit_int = 1; int Winit_cstring = 0; int Wint_to_pointer_cast = 1; int Wenum_mismatch = 1; +int Wformat = 0; int Wsparse_error = 0; int Wmemcpy_max_count = 1; int Wnon_pointer_null = 1; @@ -651,6 +652,7 @@ static const struct flag warnings[] = { { "implicit-int", &Wimplicit_int }, { "init-cstring", &Winit_cstring }, { "int-to-pointer-cast", &Wint_to_pointer_cast }, + { "format", &Wformat }, { "memcpy-max-count", &Wmemcpy_max_count }, { "non-pointer-null", &Wnon_pointer_null }, { "old-initializer", &Wold_initializer }, diff --git a/lib.h b/lib.h index 322408b..c606807 100644 --- a/lib.h +++ b/lib.h @@ -152,6 +152,7 @@ extern int Wdefault_bitfield_sign; extern int Wdesignated_init; extern int Wdo_while; extern int Wenum_mismatch; +extern int Wformat; extern int Wsparse_error; extern int Wimplicit_int; extern int Winit_cstring; diff --git a/sparse.1 b/sparse.1 index 78d0b1e..1bf4e3c 100644 --- a/sparse.1 +++ b/sparse.1 @@ -260,6 +260,15 @@ trouble. Sparse does not issue these warnings by default. . .TP +.B \-Wformat +Warn about parameter mis-match to any variadic function which specifies +where the format string is specified with the +.BI __attribute__((format( type, message, va_start ))) +attribute. + +Sparse does not issues these warnings by default. To turn them on, use +\fB\-Wno\-format\fR +.TP .B \-Wmemcpy\-max\-count Warn about call of \fBmemcpy()\fR, \fBmemset()\fR, \fBcopy_from_user()\fR, or \fBcopy_to_user()\fR with a large compile-time byte count.