linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dwaipayan Ray <dwaipayanray1@gmail.com>
To: joe@perches.com, apw@canonical.com
Cc: lukas.bulwahn@gmail.com, linux-kernel@vger.kernel.org,
	Dwaipayan Ray <dwaipayanray1@gmail.com>,
	Alejandro Colomar <alx.manpages@gmail.com>
Subject: [PATCH] checkpatch: Fix regex for do without braces
Date: Sun, 27 Jun 2021 23:53:05 +0530	[thread overview]
Message-ID: <20210627182305.4721-1-dwaipayanray1@gmail.com> (raw)

The regular expression for detecting do without braces
also passes when checkpatch encounters the "double"
keyword. This causes wrong recalculation of $stat in
checkpatch which can cause false positives.

Fix the regex to avoid the above. Also update the comments
for the check.

Reported-by: Alejandro Colomar <alx.manpages@gmail.com>
Signed-off-by: Dwaipayan Ray <dwaipayanray1@gmail.com>
---
 scripts/checkpatch.pl | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 8d19beca3538..cba68420fd55 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -5488,9 +5488,8 @@ sub process {
 			}
 		}
 
-# Check for illegal assignment in if conditional -- and check for trailing
-# statements after the conditional.
-		if ($line =~ /do\s*(?!{)/) {
+# If we have sufficient context detect and handle do without braces ({).
+		if ($line =~ /do\b\s*(?!{)/) {
 			($stat, $cond, $line_nr_next, $remain_next, $off_next) =
 				ctx_statement_block($linenr, $realcnt, 0)
 					if (!defined $stat);
@@ -5511,6 +5510,9 @@ sub process {
 								$offset} = 1;
 			}
 		}
+
+# Check for illegal assignment in if conditional -- and check for trailing
+# statements after the conditional.
 		if (!defined $suppress_whiletrailers{$linenr} &&
 		    defined($stat) && defined($cond) &&
 		    $line =~ /\b(?:if|while|for)\s*\(/ && $line !~ /^.\s*#/) {
-- 
2.28.0


                 reply	other threads:[~2021-06-27 18:23 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20210627182305.4721-1-dwaipayanray1@gmail.com \
    --to=dwaipayanray1@gmail.com \
    --cc=alx.manpages@gmail.com \
    --cc=apw@canonical.com \
    --cc=joe@perches.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lukas.bulwahn@gmail.com \
    /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;
as well as URLs for NNTP newsgroup(s).