Linux SPARSE checker discussions
 help / color / mirror / Atom feed
From: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
To: linux-sparse@vger.kernel.org
Cc: Ben Dooks <ben.dooks@codethink.co.uk>,
	Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Subject: [PATCH 1/8] need to strip SYM_NODE before comparing types
Date: Mon,  5 Oct 2020 03:59:55 +0200	[thread overview]
Message-ID: <20201005020002.1108-2-luc.vanoostenryck@gmail.com> (raw)
In-Reply-To: <20201005020002.1108-1-luc.vanoostenryck@gmail.com>

Every variable has a 'symbol type' of SYM_NODE which needs to
be stripped before comparing with builtin types like int_ctype.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
 validation/varargs-format-dyn-prec.c | 11 +++++++++++
 verify-format.c                      |  3 +++
 2 files changed, 14 insertions(+)
 create mode 100644 validation/varargs-format-dyn-prec.c

diff --git a/validation/varargs-format-dyn-prec.c b/validation/varargs-format-dyn-prec.c
new file mode 100644
index 000000000000..a143f1661c84
--- /dev/null
+++ b/validation/varargs-format-dyn-prec.c
@@ -0,0 +1,11 @@
+extern void pf(const char *msg, ...) __attribute__((format(printf, 1, 2)));
+
+static void test(int prec)
+{
+	pf("%*s\n", prec, "xyz");
+}
+
+/*
+ * check-name: variadic formatting test dynamic precision
+ * check-command: sparse -Wformat $file
+ */
diff --git a/verify-format.c b/verify-format.c
index 2da9d2069121..ba6cb5646dba 100644
--- a/verify-format.c
+++ b/verify-format.c
@@ -325,6 +325,9 @@ static int parse_format_printf_argfield(const char **fmtptr,
 	if (ctype) {
 		struct symbol *target = &int_ctype;
 
+		if (ctype->type == SYM_NODE)
+			ctype = ctype->ctype.base_type;
+
 		if (ctype != &int_ctype && ctype != &uint_ctype) {
 			warning(expr->pos, "incorrect type for %s argument %d", which, argpos);
 			info(expr->pos, "   expected %s", show_typename(target));
-- 
2.28.0


  reply	other threads:[~2020-10-05  2:00 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-05  1:59 [PATCH 0/8] format check tweaks Luc Van Oostenryck
2020-10-05  1:59 ` Luc Van Oostenryck [this message]
2020-10-05  1:59 ` [PATCH 2/8] add helper get_nth_expression() Luc Van Oostenryck
2020-10-05  1:59 ` [PATCH 3/8] move the definition of FMT_{PRINTF,SCANF} Luc Van Oostenryck
2020-10-05  1:59 ` [PATCH 4/8] parse format attribute less verbosely Luc Van Oostenryck
2020-10-05  1:59 ` [PATCH 5/8] call verify_format_attribute() unconditionally Luc Van Oostenryck
2020-10-05  2:00 ` [PATCH 6/8] s/data/type/ for struct format_type Luc Van Oostenryck
2020-10-05  2:00 ` [PATCH 7/8] add support for "%ls" Luc Van Oostenryck
2020-10-05  2:00 ` [PATCH 8/8] add support for "%Lx" (and "%Ls") Luc Van Oostenryck
2020-10-05  9:04 ` [PATCH 0/8] format check tweaks Ben Dooks
2020-10-05 23:47   ` Luc Van Oostenryck
2020-10-11 19:51     ` Ben Dooks
2020-10-12 22:38       ` Luc Van Oostenryck

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201005020002.1108-2-luc.vanoostenryck@gmail.com \
    --to=luc.vanoostenryck@gmail.com \
    --cc=ben.dooks@codethink.co.uk \
    --cc=linux-sparse@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox