diff options
author | Andy Whitcroft <apw@shadowen.org> | 2008-07-24 00:29:00 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2008-07-24 13:47:25 -0400 |
commit | a3bb97a7aba36055d476896ed6393ab35a119d5b (patch) | |
tree | 9d09ae6cfc89e72078ccf7f436fdfa7cd33a7519 | |
parent | 6ef9b297f6e8850da3be9c9ff5f00385c0977004 (diff) |
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>
-rwxr-xr-x | scripts/checkpatch.pl | 23 |
1 files changed, 11 insertions, 12 deletions
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index b2b0648ee14a..add86862325b 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl | |||
@@ -470,7 +470,9 @@ sub ctx_statement_block { | |||
470 | } | 470 | } |
471 | $off++; | 471 | $off++; |
472 | } | 472 | } |
473 | # We are truly at the end, so shuffle to the next line. | ||
473 | if ($off == $len) { | 474 | if ($off == $len) { |
475 | $loff = $len + 1; | ||
474 | $line++; | 476 | $line++; |
475 | $remain--; | 477 | $remain--; |
476 | } | 478 | } |
@@ -1793,30 +1795,26 @@ sub process { | |||
1793 | $lines[$ln - 1] =~ /^(?:-|..*\\$)/) | 1795 | $lines[$ln - 1] =~ /^(?:-|..*\\$)/) |
1794 | { | 1796 | { |
1795 | $ctx .= $rawlines[$ln - 1] . "\n"; | 1797 | $ctx .= $rawlines[$ln - 1] . "\n"; |
1798 | $cnt-- if ($lines[$ln - 1] !~ /^-/); | ||
1796 | $ln++; | 1799 | $ln++; |
1797 | $cnt--; | ||
1798 | } | 1800 | } |
1799 | $ctx .= $rawlines[$ln - 1]; | 1801 | $ctx .= $rawlines[$ln - 1]; |
1800 | 1802 | ||
1801 | ($dstat, $dcond, $ln, $cnt, $off) = | 1803 | ($dstat, $dcond, $ln, $cnt, $off) = |
1802 | ctx_statement_block($linenr, $ln - $linenr + 1, 0); | 1804 | ctx_statement_block($linenr, $ln - $linenr + 1, 0); |
1803 | #print "dstat<$dstat> dcond<$dcond> cnt<$cnt> off<$off>\n"; | 1805 | #print "dstat<$dstat> dcond<$dcond> cnt<$cnt> off<$off>\n"; |
1804 | #print "LINE<$lines[$ln]> len<" . length($lines[$ln]) . "\n"; | 1806 | #print "LINE<$lines[$ln-1]> len<" . length($lines[$ln-1]) . "\n"; |
1805 | 1807 | ||
1806 | # Extract the remainder of the define (if any) and | 1808 | # Extract the remainder of the define (if any) and |
1807 | # rip off surrounding spaces, and trailing \'s. | 1809 | # rip off surrounding spaces, and trailing \'s. |
1808 | $rest = ''; | 1810 | $rest = ''; |
1809 | if (defined $lines[$ln - 1] && | 1811 | while ($off != 0 || ($cnt > 0 && $rest =~ /(?:^|\\)\s*$/)) { |
1810 | $off > length($lines[$ln - 1])) | 1812 | #print "ADDING $off <" . substr($lines[$ln - 1], $off) . ">\n"; |
1811 | { | 1813 | if ($off != 0 || $lines[$ln - 1] !~ /^-/) { |
1812 | $ln++; | 1814 | $rest .= substr($lines[$ln - 1], $off) . "\n"; |
1813 | $cnt--; | 1815 | $cnt--; |
1814 | $off = 0; | 1816 | } |
1815 | } | ||
1816 | while ($cnt > 0) { | ||
1817 | $rest .= substr($lines[$ln - 1], $off) . "\n"; | ||
1818 | $ln++; | 1817 | $ln++; |
1819 | $cnt--; | ||
1820 | $off = 0; | 1818 | $off = 0; |
1821 | } | 1819 | } |
1822 | $rest =~ s/\\\n.//g; | 1820 | $rest =~ s/\\\n.//g; |
@@ -1847,6 +1845,7 @@ sub process { | |||
1847 | DEFINE_PER_CPU| | 1845 | DEFINE_PER_CPU| |
1848 | __typeof__\( | 1846 | __typeof__\( |
1849 | }x; | 1847 | }x; |
1848 | #print "REST<$rest>\n"; | ||
1850 | if ($rest ne '') { | 1849 | if ($rest ne '') { |
1851 | if ($rest !~ /while\s*\(/ && | 1850 | if ($rest !~ /while\s*\(/ && |
1852 | $dstat !~ /$exceptions/) | 1851 | $dstat !~ /$exceptions/) |