提交 207a8e84 编写于 作者: J Joe Perches 提交者: Linus Torvalds

checkpatch: improve UNSPECIFIED_INT test for bare signed/unsigned uses

Improve the test to allow casts to (unsigned) or (signed) to be found
and fixed if desired.
Signed-off-by: NJoe Perches <joe@perches.com>
Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
上级 a1ce18e4
...@@ -3240,10 +3240,11 @@ sub process { ...@@ -3240,10 +3240,11 @@ sub process {
next if ($line =~ /^[^\+]/); next if ($line =~ /^[^\+]/);
# check for declarations of signed or unsigned without int # check for declarations of signed or unsigned without int
while ($line =~ m{($Declare++)\s*($Ident)\s*[=,;\[\)]}g) { while ($line =~ m{($Declare)\s*(?!char\b|short\b|int\b|long\b)\s*($Ident)?\s*[=,;\[\)\(]}g) {
my $type = $1; my $type = $1;
my $var = $2; my $var = $2;
if ($type =~ /^((?:un)?signed)((?:\s*\*)*)\s*$/) { $var = "" if (!defined $var);
if ($type =~ /^(?:(?:$Storage|$Inline|$Attribute)\s+)*((?:un)?signed)((?:\s*\*)*)\s*$/) {
my $sign = $1; my $sign = $1;
my $pointer = $2; my $pointer = $2;
...@@ -3253,8 +3254,11 @@ sub process { ...@@ -3253,8 +3254,11 @@ sub process {
"Prefer '" . trim($sign) . " int" . rtrim($pointer) . "' to bare use of '$sign" . rtrim($pointer) . "'\n" . $herecurr) && "Prefer '" . trim($sign) . " int" . rtrim($pointer) . "' to bare use of '$sign" . rtrim($pointer) . "'\n" . $herecurr) &&
$fix) { $fix) {
my $decl = trim($sign) . " int "; my $decl = trim($sign) . " int ";
$decl .= trim($pointer) if (rtrim($pointer) ne ""); my $comp_pointer = $pointer;
$fixed[$fixlinenr] =~ s@\b\Q$type\E\s*$var\b@$decl$var@; $comp_pointer =~ s/\s//g;
$decl .= $comp_pointer;
$decl = rtrim($decl) if ($var eq "");
$fixed[$fixlinenr] =~ s@\b$sign\s*\Q$pointer\E\s*$var\b@$decl$var@;
} }
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册