The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Joe Perches <joe@perches.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: linux-kernel@vger.kernel.org, Hans Wennborg <hans@hanshq.net>,
	Andy Whitcroft <apw@canonical.com>
Subject: [PATCH] checkpatch: Add test for printf formats with 0x that emit decimal
Date: Sun, 03 Aug 2014 19:50:45 -0700	[thread overview]
Message-ID: <1407120645.16152.28.camel@joe-AO725> (raw)
In-Reply-To: <1407112425.16152.10.camel@joe-AO725>

0x%<foo> should be used to emit hexadecimal values.

Uses of 0x%[udi] emit decimal values but these should
probably instead use 0x%x variants.

Warn on these uses.

Signed-off-by: Joe Perches <joe@perches.com>
Noticed-by: Hans Wennborg <hans@hanshq.net>
---
 scripts/checkpatch.pl | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index da74e65..0178fe0 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -4985,6 +4985,10 @@ sub process {
 		while ($line =~ /(?:^|")([X\t]*)(?:"|$)/g) {
 			$string = substr($rawline, $-[1], $+[1] - $-[1]);
 			$string =~ s/%%/__/g;
+			if ($string =~ /(0x(?<!%)%[0-9.\*]*[Ll]*[udi])(?![xX])/) {
+				WARN("PRINTF_HEX_WITH_DECIMAL",
+				     "Using printf format $1 emits a decimal not hexadecimal value\n" . $herecurr);
+			}
 			if ($string =~ /(?<!%)%L[udi]/) {
 				WARN("PRINTF_L",
 				     "\%Ld/%Lu are not-standard C, use %lld/%llu\n" . $herecurr);



  reply	other threads:[~2014-08-04  2:50 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-02 22:20 [PATCH 1/1] cris: fix %d confusingly prefixed with 0x in format string Hans Wennborg
2014-08-03  0:46 ` Joe Perches
2014-08-03  1:19   ` Hans Wennborg
2014-08-03  6:10     ` Joe Perches
2014-08-04  0:25       ` Hans Wennborg
2014-08-04  0:33         ` Joe Perches
2014-08-04  2:50           ` Joe Perches [this message]
2014-08-04  3:03             ` [PATCH] checkpatch: Add test for printf formats with 0x that emit decimal Hans Wennborg
2014-08-04  3:46               ` Joe Perches
2014-08-05  1:17                 ` Hans Wennborg
2014-08-03  2:26   ` [PATCH 1/1] cris: fix %d confusingly prefixed with 0x in format string Steve French

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=1407120645.16152.28.camel@joe-AO725 \
    --to=joe@perches.com \
    --cc=akpm@linux-foundation.org \
    --cc=apw@canonical.com \
    --cc=hans@hanshq.net \
    --cc=linux-kernel@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