checkpatch: ensure we do not collapse bracketed sections into constants

When determining if a return () sequence is a function style bracketing we
simplify the expression one bracket at a time replacing each with a
constant.  However this can trigger a false merge with expressions as
below:

	return (foo)0;

Prevent this false merging.

Reported-by: Hitoshi Mitake <mitake@dcl.info.waseda.ac.jp>
Signed-off-by: Andy Whitcroft <apw@canonical.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
Andy Whitcroft 2010-10-26 14:23:12 -07:00 committed by Linus Torvalds
parent d2c0a23514
commit fb2d2c1b58
1 changed files with 4 additions and 3 deletions

View File

@ -2183,15 +2183,16 @@ sub process {
my $value = $2; my $value = $2;
# Flatten any parentheses # Flatten any parentheses
$value =~ s/\)\(/\) \(/g; $value =~ s/\(/ \(/g;
$value =~ s/\)/\) /g;
while ($value =~ s/\[[^\{\}]*\]/1/ || while ($value =~ s/\[[^\{\}]*\]/1/ ||
$value !~ /(?:$Ident|-?$Constant)\s* $value !~ /(?:$Ident|-?$Constant)\s*
$Compare\s* $Compare\s*
(?:$Ident|-?$Constant)/x && (?:$Ident|-?$Constant)/x &&
$value =~ s/\([^\(\)]*\)/1/) { $value =~ s/\([^\(\)]*\)/1/) {
} }
#print "value<$value>\n";
if ($value =~ /^(?:$Ident|-?$Constant)$/) { if ($value =~ /^\s*(?:$Ident|-?$Constant)\s*$/) {
ERROR("return is not a function, parentheses are not required\n" . $herecurr); ERROR("return is not a function, parentheses are not required\n" . $herecurr);
} elsif ($spacing !~ /\s+/) { } elsif ($spacing !~ /\s+/) {