Browse Source

checkpatch: ensure we only apply checks to the lines within hunks

We should only apply source checks to lines within hunks.  Checks which
are anchored in the context may falsly trigger in the commentory.  Ensure
they only match within valid hunk 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>
Andy Whitcroft 16 years ago
parent
commit
306708547b
1 changed files with 3 additions and 2 deletions
  1. 3 2
      scripts/checkpatch.pl

+ 3 - 2
scripts/checkpatch.pl

@@ -1128,6 +1128,7 @@ sub process {
 		$linenr++;
 		$linenr++;
 
 
 		my $rawline = $rawlines[$linenr - 1];
 		my $rawline = $rawlines[$linenr - 1];
+		my $hunk_line = ($realcnt != 0);
 
 
 #extract the line range in the file after the patch is applied
 #extract the line range in the file after the patch is applied
 		if ($line=~/^\@\@ -\d+(?:,\d+)? \+(\d+)(,(\d+))? \@\@/) {
 		if ($line=~/^\@\@ -\d+(?:,\d+)? \+(\d+)(,(\d+))? \@\@/) {
@@ -1238,8 +1239,8 @@ sub process {
 			ERROR("Invalid UTF-8, patch and commit message should be encoded in UTF-8\n" . $hereptr);
 			ERROR("Invalid UTF-8, patch and commit message should be encoded in UTF-8\n" . $hereptr);
 		}
 		}
 
 
-#ignore lines being removed
-		if ($line=~/^-/) {next;}
+# ignore non-hunk lines and lines being removed
+		next if (!$hunk_line || $line =~ /^-/);
 
 
 #trailing whitespace
 #trailing whitespace
 		if ($line =~ /^\+.*\015/) {
 		if ($line =~ /^\+.*\015/) {