checkpatch: macros: fix statement counting block end detection
We are incorrectly counting the lines in a block while accumulating the trailing lines in a macro statement, leading to false positives. Fix end of block handling and general counting for negative context lines. Signed-off-by: Andy Whitcroft <apw@shadowen.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
Родитель
6ef9b297f6
Коммит
a3bb97a7ab
|
@ -470,7 +470,9 @@ sub ctx_statement_block {
|
||||||
}
|
}
|
||||||
$off++;
|
$off++;
|
||||||
}
|
}
|
||||||
|
# We are truly at the end, so shuffle to the next line.
|
||||||
if ($off == $len) {
|
if ($off == $len) {
|
||||||
|
$loff = $len + 1;
|
||||||
$line++;
|
$line++;
|
||||||
$remain--;
|
$remain--;
|
||||||
}
|
}
|
||||||
|
@ -1793,30 +1795,26 @@ sub process {
|
||||||
$lines[$ln - 1] =~ /^(?:-|..*\\$)/)
|
$lines[$ln - 1] =~ /^(?:-|..*\\$)/)
|
||||||
{
|
{
|
||||||
$ctx .= $rawlines[$ln - 1] . "\n";
|
$ctx .= $rawlines[$ln - 1] . "\n";
|
||||||
|
$cnt-- if ($lines[$ln - 1] !~ /^-/);
|
||||||
$ln++;
|
$ln++;
|
||||||
$cnt--;
|
|
||||||
}
|
}
|
||||||
$ctx .= $rawlines[$ln - 1];
|
$ctx .= $rawlines[$ln - 1];
|
||||||
|
|
||||||
($dstat, $dcond, $ln, $cnt, $off) =
|
($dstat, $dcond, $ln, $cnt, $off) =
|
||||||
ctx_statement_block($linenr, $ln - $linenr + 1, 0);
|
ctx_statement_block($linenr, $ln - $linenr + 1, 0);
|
||||||
#print "dstat<$dstat> dcond<$dcond> cnt<$cnt> off<$off>\n";
|
#print "dstat<$dstat> dcond<$dcond> cnt<$cnt> off<$off>\n";
|
||||||
#print "LINE<$lines[$ln]> len<" . length($lines[$ln]) . "\n";
|
#print "LINE<$lines[$ln-1]> len<" . length($lines[$ln-1]) . "\n";
|
||||||
|
|
||||||
# Extract the remainder of the define (if any) and
|
# Extract the remainder of the define (if any) and
|
||||||
# rip off surrounding spaces, and trailing \'s.
|
# rip off surrounding spaces, and trailing \'s.
|
||||||
$rest = '';
|
$rest = '';
|
||||||
if (defined $lines[$ln - 1] &&
|
while ($off != 0 || ($cnt > 0 && $rest =~ /(?:^|\\)\s*$/)) {
|
||||||
$off > length($lines[$ln - 1]))
|
#print "ADDING $off <" . substr($lines[$ln - 1], $off) . ">\n";
|
||||||
{
|
if ($off != 0 || $lines[$ln - 1] !~ /^-/) {
|
||||||
|
$rest .= substr($lines[$ln - 1], $off) . "\n";
|
||||||
|
$cnt--;
|
||||||
|
}
|
||||||
$ln++;
|
$ln++;
|
||||||
$cnt--;
|
|
||||||
$off = 0;
|
|
||||||
}
|
|
||||||
while ($cnt > 0) {
|
|
||||||
$rest .= substr($lines[$ln - 1], $off) . "\n";
|
|
||||||
$ln++;
|
|
||||||
$cnt--;
|
|
||||||
$off = 0;
|
$off = 0;
|
||||||
}
|
}
|
||||||
$rest =~ s/\\\n.//g;
|
$rest =~ s/\\\n.//g;
|
||||||
|
@ -1847,6 +1845,7 @@ sub process {
|
||||||
DEFINE_PER_CPU|
|
DEFINE_PER_CPU|
|
||||||
__typeof__\(
|
__typeof__\(
|
||||||
}x;
|
}x;
|
||||||
|
#print "REST<$rest>\n";
|
||||||
if ($rest ne '') {
|
if ($rest ne '') {
|
||||||
if ($rest !~ /while\s*\(/ &&
|
if ($rest !~ /while\s*\(/ &&
|
||||||
$dstat !~ /$exceptions/)
|
$dstat !~ /$exceptions/)
|
||||||
|
|
Загрузка…
Ссылка в новой задаче