From: Su Hang <suhang16@mails.ucas.ac.cn>
To: stefanha@gmail.com, jim@groklearning.com, joel@jms.id.au,
qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH v2] scripts/checkpatch.pl: Bug fix
Date: Tue, 3 Apr 2018 23:17:13 +0800 [thread overview]
Message-ID: <1522768634-5548-3-git-send-email-suhang16@mails.ucas.ac.cn> (raw)
In-Reply-To: <1522768634-5548-1-git-send-email-suhang16@mails.ucas.ac.cn>
checkpatch.pl stops complaining about following pattern:
"""
do {
//do somethins;
} while (conditions);
"""
One things need to be mentioned:
Becasue `if`, `while` and `for` check have been done in this
`if` block(Line: 2356), and this block contains following statement:
""" Line: 2379
$suppress_ifbraces{$ln + $offset} = 1;
"""
So the behind block may never run:
""" Line: 2415
if (!defined $suppress_ifbraces{$linenr - 1} &&
$line =~ /\b(if|while|for|else)\b/ &&
$line !~ /\#\s*if/ &&
$line !~ /\#\s*else/) {
"""
I'm not sure, please give me some advice.
(Sorry, I don't know this patch should base on which commit,
so I generate this patch based on
commit:fb8446d94ec7a3dc0c3a7e7da672406476f075ac,
I choose this by `git log -2 scripts/checkpath.pl`.
Sincerely say sorry, if I have misunderstand any meaning.)
Signed-off-by: Su Hang <suhang16@mails.ucas.ac.cn>
---
scripts/checkpatch.pl | 21 +++++++++++++++++----
1 file changed, 17 insertions(+), 4 deletions(-)
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index a88af61ed4ee..d6f0747ba20a 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -2352,8 +2352,22 @@ sub process {
}
}
-# check for missing bracing round if etc
- if ($line =~ /(^.*)\bif\b/ && $line !~ /\#\s*if/) {
+# check for missing bracing around if etc
+ if ($line =~ /(^.*)\b(?:if|while|for)\b/ &&
+ $line !~ /\#\s*if/) {
+ my $allowed = 0;
+
+ # Check the pre-context.
+ if ($line =~ /(\}.*?)$/) {
+ my $pre = $1;
+
+ if ($line !~ /else/) {
+ print "APW: ALLOWED: pre<$pre> line<$line>\n"
+ if $dbg_adv_apw;
+ $allowed = 1;
+ }
+ }
+
my ($level, $endln, @chunks) =
ctx_statement_full($linenr, $realcnt, 1);
if ($dbg_adv_apw) {
@@ -2362,7 +2376,6 @@ sub process {
if $#chunks >= 1;
}
if ($#chunks >= 0 && $level == 0) {
- my $allowed = 0;
my $seen = 0;
my $herectx = $here . "\n";
my $ln = $linenr - 1;
@@ -2406,7 +2419,7 @@ sub process {
$allowed = 1;
}
}
- if ($seen != ($#chunks + 1)) {
+ if ($seen != ($#chunks + 1) && !$allowed) {
ERROR("braces {} are necessary for all arms of this statement\n" . $herectx);
}
}
--
2.7.4
next prev parent reply other threads:[~2018-04-03 15:17 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-04-03 15:17 [Qemu-devel] [PATCH 0/2 RFC] Implement Hex file loader and add test case Su Hang
2018-04-03 15:17 ` [Qemu-devel] [PATCH 1/2] Implement .hex file loader Su Hang
2018-04-03 15:17 ` Su Hang [this message]
2018-04-03 15:29 ` [Qemu-devel] [PATCH v2] scripts/checkpatch.pl: Bug fix Su Hang
2018-04-03 15:17 ` [Qemu-devel] [PATCH 2/2] Add QTest testcase for the Hex File Loader Su Hang
2018-04-03 15:25 ` [Qemu-devel] [PATCH 0/2 RFC] Implement Hex file loader and add test case no-reply
-- strict thread matches above, loose matches on Subject: below --
2018-03-16 2:58 [Qemu-devel] [PATCH v2] scripts/checkpatch.pl: Bug fix Su Hang
2018-03-16 6:15 ` Fam Zheng
2018-03-16 6:31 ` Su Hang
2018-03-16 7:08 ` Fam Zheng
2018-03-16 7:13 ` Su Hang
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=1522768634-5548-3-git-send-email-suhang16@mails.ucas.ac.cn \
--to=suhang16@mails.ucas.ac.cn \
--cc=jim@groklearning.com \
--cc=joel@jms.id.au \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@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).