From: 苏航 <suhang16@mails.ucas.ac.cn>
To: Eric Blake <eblake@redhat.com>
Cc: Thomas Huth <thuth@redhat.com>,
stefanha@redhat.com, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH v3 3/3] util/uri.c: add brackets to `if` statements
Date: Sat, 24 Feb 2018 20:56:53 +0800 (GMT+08:00) [thread overview]
Message-ID: <1a2f136b.13907.161c7e33cc9.Coremail.suhang16@mails.ucas.ac.cn> (raw)
In-Reply-To: <12b54434-c992-d882-9ce7-0f658d067a7c@redhat.com>
Hi, when I try to change
`while (cond) ;`
to
`while (cond) {
}`
checkpatch.pl complains about this:
'''
ERROR: suspect code indent for conditional statements (8, 8)
#1506: FILE: uri.c:1506:
+ while ((*tmp++ = *segp++) != 0) {
[...]
+ }
ERROR: suspect code indent for conditional statements (8, 8)
#1512: FILE: uri.c:1512:
+ while ((segp > path) && ((--segp)[0] == '/')) {
[...]
+ }
'''
When I add a semicolon, checkpatch.pl stop complaining.
`while (cond) {
;
}`
What should I do now?
"Eric Blake" <eblake@redhat.com>wrote:
> On 02/23/2018 03:34 AM, Thomas Huth wrote:
> > On 23.02.2018 08:51, Su Hang wrote:
> >> Add brackets that wrap `if`, `else`, `while` that hold single
> >> statements.
> >>
> >> In order to do this, I write a simple python regex script.
>
> Without documenting the script, no one else can reproduce this; but it's
> no different than if they had manually made changes instead of trying to
> script it, so I'm not sure this sentence adds much in its current form.
>
> >>
> >> Since then, all complaints rised by checkpatch.pl has been suppressed.
>
> s/rised/raised/
> s/Since then,/With that/
> s/has/have/
>
> >>
> >> Signed-off-by: Su Hang <suhang16@mails.ucas.ac.cn>
> >> ---
> >> util/uri.c | 462 ++++++++++++++++++++++++++++++++++++++-----------------------
> >> 1 file changed, 291 insertions(+), 171 deletions(-)
> >>
>
> >> cur = *str;
> >> - if (!ISA_ALPHA(cur))
> >> + if (!ISA_ALPHA(cur)) {
> >> return 2;
> >> + }
> >> cur++;
> >> - while (ISA_ALPHA(cur) || ISA_DIGIT(cur) ||
> >> - (*cur == '+') || (*cur == '-') || (*cur == '.'))
> >> + while (ISA_ALPHA(cur) || ISA_DIGIT(cur) || (*cur == '+') || (*cur == '-') ||
> >> + (*cur == '.'))
> >> cur++;
> >
> > You've changed the while statement, but checkpatch.pl apparently does not
> > complain about missing curly braces here ... that's strange, I thought we'd
> > also wanted to enforce curly braces for while loops.
>
> Maybe because it gets lost since the condition expanded over more than
> one line? But yes, now that we've noticed it manually, it should be
> fixed. While at it, you can avoid the redundant ():
>
> while (ISA_ALPHA(cur) || ISA_DIGIT(cur) || *cur == '+' || *cur == '-' ||
> *cur == '.') {
>
>
> >> - while ((*tmp++ = *segp++) != 0)
> >> + while ((*tmp++ = *segp++) != 0) {
> >> ;
> >> + }
> >
> > A bikeshed-painting-friday question for everybody on qemu-devel:
> > Should there be a single semicolon inside curly braces in this case, or not?
> >
>
> Checkpatch doesn't complain, but lone ';' statements are rare. I'd omit
> it, and use just:
>
> while (cond) {
> }
>
>
> --
> Eric Blake, Principal Software Engineer
> Red Hat, Inc. +1-919-301-3266
> Virtualization: qemu.org | libvirt.org
next prev parent reply other threads:[~2018-02-24 12:57 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-02-23 7:51 [Qemu-devel] [PATCH v3 3/3] util/uri.c: add brackets to `if` statements Su Hang
2018-02-23 9:34 ` Thomas Huth
2018-02-23 14:55 ` 苏航
2018-02-23 14:55 ` Eric Blake
2018-02-24 11:10 ` 苏航
2018-02-24 12:56 ` 苏航 [this message]
2018-02-24 19:09 ` Eric Blake
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=1a2f136b.13907.161c7e33cc9.Coremail.suhang16@mails.ucas.ac.cn \
--to=suhang16@mails.ucas.ac.cn \
--cc=eblake@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
--cc=thuth@redhat.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).