[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 80/92] checkpatch: Detect '%#' or '%0#' in printf-style format str
From: |
Paolo Bonzini |
Subject: |
[PULL 80/92] checkpatch: Detect '%#' or '%0#' in printf-style format strings |
Date: |
Thu, 24 Sep 2020 05:23:02 -0400 |
From: Dov Murik <dovmurik@linux.vnet.ibm.com>
According to the coding style document, we should use literal '0x' prefix
instead of printf's '#' flag (which appears as '%#' or '%0#' in the format
string). Add a checkpatch rule to enforce that.
Note that checkpatch already had a similar rule for trace-events files.
Example usage:
$ scripts/checkpatch.pl --file chardev/baum.c
...
ERROR: Don't use '#' flag of printf format ('%#') in format strings, use '0x'
prefix instead
#366: FILE: chardev/baum.c:366:
+ DPRINTF("Broken packet %#2x, tossing\n", req); \
...
ERROR: Don't use '#' flag of printf format ('%#') in format strings, use '0x'
prefix instead
#472: FILE: chardev/baum.c:472:
+ DPRINTF("unrecognized request %0#2x\n", req);
...
Signed-off-by: Dov Murik <dovmurik@linux.vnet.ibm.com>
Message-Id: <20200914172623.72955-1-dovmurik@linux.vnet.ibm.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
scripts/checkpatch.pl | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 22bb634c8e..83967d9c6e 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -2880,14 +2880,20 @@ sub process {
$herecurr);
}
-# check for %L{u,d,i} in strings
+# format strings checks
my $string;
while ($line =~ /(?:^|")([X\t]*)(?:"|$)/g) {
$string = substr($rawline, $-[1], $+[1] - $-[1]);
$string =~ s/%%/__/g;
+ # check for %L{u,d,i} in strings
if ($string =~ /(?<!%)%L[udi]/) {
ERROR("\%Ld/%Lu are not-standard C, use
%lld/%llu\n" . $herecurr);
- last;
+ }
+ # check for %# or %0# in printf-style format strings
+ if ($string =~ /(?<!%)%0?#/) {
+ ERROR("Don't use '#' flag of printf format " .
+ "('%#') in format strings, use '0x' " .
+ "prefix instead\n" . $herecurr);
}
}
--
2.26.2
- [PULL 66/92] qom: Document all function parameters in doc comments, (continued)
- [PULL 66/92] qom: Document all function parameters in doc comments, Paolo Bonzini, 2020/09/24
- [PULL 67/92] qom: Use kernel-doc private/public tags in structs, Paolo Bonzini, 2020/09/24
- [PULL 68/92] qom: Use ``code`` Sphinx syntax where appropriate, Paolo Bonzini, 2020/09/24
- [PULL 69/92] qom: Add kernel-doc markup to introduction doc comment, Paolo Bonzini, 2020/09/24
- [PULL 70/92] qom: Reformat section titles using Sphinx syntax, Paolo Bonzini, 2020/09/24
- [PULL 71/92] qom: Indent existing code examples, Paolo Bonzini, 2020/09/24
- [PULL 72/92] qom: Add code block markup to all code blocks, Paolo Bonzini, 2020/09/24
- [PULL 73/92] docs: Create docs/devel/qom.rst, Paolo Bonzini, 2020/09/24
- [PULL 74/92] docs: Move object.h overview doc comment to qom.rst, Paolo Bonzini, 2020/09/24
- [PULL 75/92] hw/i386/xen: Rename X86/PC specific function as xen_hvm_init_pc(), Paolo Bonzini, 2020/09/24
- [PULL 80/92] checkpatch: Detect '%#' or '%0#' in printf-style format strings,
Paolo Bonzini <=
- [PULL 87/92] hw/net/can: sja1000 ignore CAN FD frames, Paolo Bonzini, 2020/09/24
- [PULL 76/92] sysemu/xen: Add missing 'exec/cpu-common.h' header for ram_addr_t type, Paolo Bonzini, 2020/09/24
- [PULL 78/92] hw/xen: Split x86-specific declaration from generic hardware ones, Paolo Bonzini, 2020/09/24
- [PULL 77/92] stubs: Split accelerator / hardware related stubs, Paolo Bonzini, 2020/09/24
- [PULL 85/92] target/i386: kvm: do not use kvm_check_extension to find paravirtual capabilities, Paolo Bonzini, 2020/09/24
- [PULL 86/92] net/can: Initial host SocketCan support for CAN FD., Paolo Bonzini, 2020/09/24
- [PULL 79/92] typedefs: Restrict PCMachineState to 'hw/i386/pc.h', Paolo Bonzini, 2020/09/24
- [PULL 82/92] target/i386: Fix VM migration when interrupt based APF is enabled, Paolo Bonzini, 2020/09/24
- [PULL 83/92] target/i386: always create kvmclock device, Paolo Bonzini, 2020/09/24
- [PULL 81/92] helper_syscall x86_64: clear exception_is_int, Paolo Bonzini, 2020/09/24