Skip to content

Commit

Permalink
checkpatch: improve UNSPECIFIED_INT test for bare signed/unsigned uses
Browse files Browse the repository at this point in the history
Improve the test to allow casts to (unsigned) or (signed) to be found
and fixed if desired.

Signed-off-by: Joe Perches <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
JoePerches authored and torvalds committed Mar 15, 2016
1 parent a1ce18e commit 207a8e8
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions scripts/checkpatch.pl
Original file line number Diff line number Diff line change
Expand Up @@ -3240,10 +3240,11 @@ sub process {
next if ($line =~ /^[^\+]/);

# 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 $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 $pointer = $2;

Expand All @@ -3253,8 +3254,11 @@ sub process {
"Prefer '" . trim($sign) . " int" . rtrim($pointer) . "' to bare use of '$sign" . rtrim($pointer) . "'\n" . $herecurr) &&
$fix) {
my $decl = trim($sign) . " int ";
$decl .= trim($pointer) if (rtrim($pointer) ne "");
$fixed[$fixlinenr] =~ s@\b\Q$type\E\s*$var\b@$decl$var@;
my $comp_pointer = $pointer;
$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@;
}
}
}
Expand Down

0 comments on commit 207a8e8

Please sign in to comment.