[prev in list] [next in list] [prev in thread] [next in thread] 

List:       linux-sparse
Subject:    [PATCH 4/5] add -Wformat
From:       Ben Dooks <ben.dooks () codethink ! co ! uk>
Date:       2019-04-04 11:57:33
Message-ID: 20190404115734.2403-5-ben.dooks () codethink ! co ! uk
[Download RAW message or body]

Add option to enable/disable format checking (and default it to off)

Signed-off-by: Ben Dooks <ben.dooks@codethink.co.uk>
---
Changes since v1:
- Default -Wformat off

Changes since v2:
- Spelling fixes

fixup format docs
---
 evaluate.c | 4 ++--
 lib.c      | 2 ++
 lib.h      | 1 +
 sparse.1   | 9 +++++++++
 4 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/evaluate.c b/evaluate.c
index 001b8e0..539b0c7 100644
--- a/evaluate.c
+++ b/evaluate.c
@@ -2761,7 +2761,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 by degenerate()
 	 */
-	if (fn->ctype.printf_va_start)
+	if (Wformat && fn->ctype.printf_va_start)
 		fmt_string = get_printf_fmt(fn, head);
 
 	PREPARE_PTR_LIST(argument_types, argtype);
@@ -2801,7 +2801,7 @@ static int evaluate_arguments(struct symbol *fn, struct expression_list *head)
 	} END_FOR_EACH_PTR(expr);
 	FINISH_PTR_LIST(argtype);
 
-	if (fn->ctype.printf_va_start)
+	if (Wformat && fn->ctype.printf_va_start)
 		evaluate_format_printf(fmt_string, fn, head);
 
 	return 1;
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..af9a428 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 mismatch 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 issue 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.
-- 
2.20.1

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic