mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andy Whitcroft <apw@canonical.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Ingo Molnar <mingo@elte.hu>,
	linux-kernel@vger.kernel.org, Andy Whitcroft <apw@canonical.com>
Subject: [PATCH 15/16] checkpatch: statement/block context analyser should look at sanitised lines
Date: Wed, 18 Aug 2010 16:46:48 +0100	[thread overview]
Message-ID: <1282146409-30544-16-git-send-email-apw@canonical.com> (raw)
In-Reply-To: <1282146409-30544-1-git-send-email-apw@canonical.com>

When tracking context to find a block or statement we need to use the
sanitised lines, else perentheses '(' & ')' and braces '{' & '}' can
throw the scanner out.  Also fix up a couple of error outputs which
include those sanitised lines incorrectly.

Signed-off-by: Andy Whitcroft <apw@canonical.com>
---
 scripts/checkpatch.pl |   12 ++++++------
 1 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 8ab45b7..d086ffe 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -691,15 +691,15 @@ sub ctx_block_get {
 		$blk .= $rawlines[$line];
 
 		# Handle nested #if/#else.
-		if ($rawlines[$line] =~ /^.\s*#\s*(?:ifndef|ifdef|if)\s/) {
+		if ($lines[$line] =~ /^.\s*#\s*(?:ifndef|ifdef|if)\s/) {
 			push(@stack, $level);
-		} elsif ($rawlines[$line] =~ /^.\s*#\s*(?:else|elif)\b/) {
+		} elsif ($lines[$line] =~ /^.\s*#\s*(?:else|elif)\b/) {
 			$level = $stack[$#stack - 1];
-		} elsif ($rawlines[$line] =~ /^.\s*#\s*endif\b/) {
+		} elsif ($lines[$line] =~ /^.\s*#\s*endif\b/) {
 			$level = pop(@stack);
 		}
 
-		foreach my $c (split(//, $rawlines[$line])) {
+		foreach my $c (split(//, $lines[$line])) {
 			##print "C<$c>L<$level><$open$close>O<$off>\n";
 			if ($off > 0) {
 				$off--;
@@ -1652,7 +1652,7 @@ sub process {
 
 			if ($ctx !~ /{\s*/ && defined($lines[$ctx_ln -1]) && $lines[$ctx_ln - 1] =~ /^\+\s*{/) {
 				ERROR("that open brace { should be on the previous line\n" .
-					"$here\n$ctx\n$lines[$ctx_ln - 1]\n");
+					"$here\n$ctx\n$rawlines[$ctx_ln - 1]\n");
 			}
 			if ($level == 0 && $pre_ctx !~ /}\s*while\s*\($/ &&
 			    $ctx =~ /\)\s*\;\s*$/ &&
@@ -1661,7 +1661,7 @@ sub process {
 				my ($nlength, $nindent) = line_stats($lines[$ctx_ln - 1]);
 				if ($nindent > $indent) {
 					WARN("trailing semicolon indicates no statements, indent implies otherwise\n" .
-						"$here\n$ctx\n$lines[$ctx_ln - 1]\n");
+						"$here\n$ctx\n$rawlines[$ctx_ln - 1]\n");
 				}
 			}
 		}
-- 
1.7.0.4


  parent reply	other threads:[~2010-08-18 15:47 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-08-18 15:46 [PATCH 00/16] update checkpatch to v0.31 Andy Whitcroft
2010-08-18 15:46 ` [PATCH 01/16] checkpatch: fix regressions in "fix handling of leading spaces" Andy Whitcroft
2010-08-18 15:46 ` [PATCH 02/16] checkpatch: types may sit on a line on their own Andy Whitcroft
2010-08-18 15:46 ` [PATCH 03/16] checkpatch: suggest cleanpatch and cleanfile when appropriate Andy Whitcroft
2010-08-18 15:46 ` [PATCH 04/16] checkpatch: ensure we do not collapse bracketed sections into constants Andy Whitcroft
2010-08-18 15:46 ` [PATCH 05/16] checkpatch: handle casts better fixing false categorisation of : as binary Andy Whitcroft
2010-08-18 15:46 ` [PATCH 06/16] checkpatch: returning errno typically should be negative Andy Whitcroft
2010-08-18 15:46 ` [PATCH 07/16] checkpatch: add check for space after struct, union, and enum Andy Whitcroft
2010-08-18 15:46 ` [PATCH 08/16] checkpatch: simplify and consolidate "missing space after" checks Andy Whitcroft
2010-08-18 15:46 ` [PATCH 09/16] checkpatch: ensure kconfig help checks only apply when we are adding help Andy Whitcroft
2010-08-18 15:46 ` [PATCH 10/16] checkpatch: check for incorrect permissions Andy Whitcroft
2010-08-18 15:46 ` [PATCH 11/16] checkpatch: Add additional attribute #defines Andy Whitcroft
2010-08-18 15:46 ` [PATCH 12/16] checkpatch: update copyright dates Andy Whitcroft
2010-08-18 15:46 ` [PATCH 13/16] checkpatch: clean up structure definition macro handline Andy Whitcroft
2010-08-18 15:46 ` [PATCH 14/16] checkpatch: handle EXPORT_SYMBOL for DEVICE_ATTR and similar Andy Whitcroft
2010-08-18 15:46 ` Andy Whitcroft [this message]
2010-08-18 15:46 ` [PATCH 16/16] checkpatch: version 0.31 Andy Whitcroft

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1282146409-30544-16-git-send-email-apw@canonical.com \
    --to=apw@canonical.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®