From 89fdd6ffcbde42acb63f10e10b9a222db699ef2d Mon Sep 17 00:00:00 2001 From: Joe Perches Date: Wed, 19 Jun 2013 10:07:21 +1000 Subject: [PATCH] checkpatch: improve "no space after cast" test Some false positives exist on this test. For instance: *va_arg(args, signed char *) = val.s; or memset(foo, 0, sizeof(struct bar *) * baz)); Ignore lines that have an arithmetic operator or assignment after what appears to be a cast to a pointer "(foo *)". Add $Arithmetic convenience variable. Signed-off-by: Joe Perches Signed-off-by: Andrew Morton --- scripts/checkpatch.pl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index c2d223c406e8..ab39ceb38286 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -241,10 +241,11 @@ our $Float = qr{$Float_hex|$Float_dec|$Float_int}; our $Constant = qr{$Float|$Binary|$Hex|$Int}; our $Assignment = qr{\*\=|/=|%=|\+=|-=|<<=|>>=|&=|\^=|\|=|=}; our $Compare = qr{<=|>=|==|!=|<|>}; +our $Arithmetic = qr{\+|-|\*|\/|%}; our $Operators = qr{ <=|>=|==|!=| =>|->|<<|>>|<|>|!|~| - &&|\|\||,|\^|\+\+|--|&|\||\+|-|\*|\/|% + &&|\|\||,|\^|\+\+|--|&|\||$Arithmetic }x; our $NonptrType; @@ -1885,7 +1886,7 @@ sub process { } } - if ($line =~ /^\+.*\*[ \t]*\)[ \t]+/) { + if ($line =~ /^\+.*\*[ \t]*\)[ \t]+(?!$Assignment|$Arithmetic)/) { CHK("SPACING", "No space is necessary after a cast\n" . $hereprev); } -- 2.39.5