Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1764642AbdAJCLe (ORCPT ); Mon, 9 Jan 2017 21:11:34 -0500 Received: from smtprelay0082.hostedemail.com ([216.40.44.82]:56615 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1764611AbdAJCLc (ORCPT ); Mon, 9 Jan 2017 21:11:32 -0500 X-Session-Marker: 6A6F6540706572636865732E636F6D X-Spam-Summary: 2,0,0,,d41d8cd98f00b204,joe@perches.com,:::::::,RULES_HIT:41:69:355:379:541:800:960:973:982:988:989:1260:1345:1431:1437:1534:1542:1711:1730:1747:1777:1792:2197:2198:2199:2200:2282:2393:2559:2562:3138:3139:3140:3141:3142:3353:3653:3865:3866:3867:3868:3870:3871:4250:4605:5007:6261:7514:7576:7903:10004:10848:11232:11658:11914:12043:12296:12555:12663:12679:12895:13149:13230:14181:14394:14721:21080:21221:21324:21451:30054:30056:30070,0,RBL:none,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fn,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:2,LUA_SUMMARY:none X-HE-Tag: boats98_2a25662203310 X-Filterd-Recvd-Size: 3266 From: Joe Perches To: Andrew Morton , Andy Whitcroft Cc: Alexey Dobriyan , linux-kernel@vger.kernel.org Subject: [PATCH] checkpatch: warn when formats use %Z and suggest %z Date: Mon, 9 Jan 2017 18:11:26 -0800 Message-Id: <4e3ad74b0c9dc229b06018a2d79655308ddbbebd.1484014173.git.joe@perches.com> X-Mailer: git-send-email 2.10.0.rc2.1.g053435c Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Alexey Dobriyan vsnprintf extension %Z is non-standard C. Suggest the use of %z instead. Miscellanea: o Correct the misuse of type string PRINTF_0xDECIMAL type strings are supposed to be uppercase only. Fix this and add tr/[a-z]/[A-Z] to the type check in case I forget this again sometime in the future. o Improve the mechanism to find these defects so all 3 current checks are done on the format string Signed-off-by: Alexey Dobriyan Signed-off-by: Joe Perches --- I'll assume Alexey is OK with this modification to the patch he created. scripts/checkpatch.pl | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 99babcdf1dd8..89a7ad69d4fe 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -1848,6 +1848,8 @@ my $prefix = ''; sub show_type { my ($type) = @_; + $type =~ tr/[a-z]/[A-Z]/; + return defined $use_type{$type} if (scalar keys %use_type > 0); return !defined $ignore_type{$type}; @@ -5179,24 +5181,27 @@ sub process { "Consecutive strings are generally better as a single string\n" . $herecurr); } -# check for %L{u,d,i} and 0x%[udi] in strings - my $string; +# check for non-standard and hex prefixed decimal printf formats + my $show_L = 1; #don't show the same defect twice + my $show_Z = 1; while ($line =~ /(?:^|")([X\t]*)(?:"|$)/g) { - $string = substr($rawline, $-[1], $+[1] - $-[1]); + my $string = substr($rawline, $-[1], $+[1] - $-[1]); $string =~ s/%%/__/g; - if ($string =~ /(? + if ($string =~ /0x%[\*\d\.\$\Llzth]*[diou]/) { + ERROR("PRINTF_0XDECIMAL", "Prefixing 0x with decimal output is defective\n" . $herecurr); } } -- 2.10.0.rc2.1.g053435c