Skip to content

Commit

Permalink
checkpatch: emit an error on formats with 0x%<decimal>
Browse files Browse the repository at this point in the history
Using 0x%d is wrong.  Emit a message when it happens.

Miscellanea:

Improve the %Lu warning to match formats like %16Lu.

Signed-off-by: Joe Perches <joe@perches.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
  • Loading branch information
Joe Perches authored and Linus Torvalds committed Sep 10, 2015
1 parent 7bd7e48 commit 6e30075
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions scripts/checkpatch.pl
Original file line number Diff line number Diff line change
Expand Up @@ -4816,16 +4816,20 @@ sub process {
"Consecutive strings are generally better as a single string\n" . $herecurr);
}

# check for %L{u,d,i} in strings
# check for %L{u,d,i} and 0x%[udi] in strings
my $string;
while ($line =~ /(?:^|")([X\t]*)(?:"|$)/g) {
$string = substr($rawline, $-[1], $+[1] - $-[1]);
$string =~ s/%%/__/g;
if ($string =~ /(?<!%)%L[udi]/) {
if ($string =~ /(?<!%)%[\*\d\.\$]*L[udi]/) {
WARN("PRINTF_L",
"\%Ld/%Lu are not-standard C, use %lld/%llu\n" . $herecurr);
last;
}
if ($string =~ /0x%[\*\d\.\$\Llzth]*[udi]/) {
ERROR("PRINTF_0xDECIMAL",
"Prefixing 0x with decimal output is defective\n" . $herecurr);
}
}

# check for line continuations in quoted strings with odd counts of "
Expand Down

0 comments on commit 6e30075

Please sign in to comment.