* [Qemu-devel] [PATCH v2] checkpatch: Don't emit spurious warnings about block comments
@ 2019-01-18 16:50 Peter Maydell
2019-01-18 17:06 ` Eric Blake
0 siblings, 1 reply; 3+ messages in thread
From: Peter Maydell @ 2019-01-18 16:50 UTC (permalink / raw)
To: qemu-devel; +Cc: patches, Thomas Huth, Eric Blake
In checkpatch we attempt to check for and warn about
block comments which start with /* or /** followed by a
non-blank. Unfortunately a bug in the regex meant that
we would incorrectly warn about comments starting with
"/**" with no following text:
git show 9813dc6ac3954d58ba16b3920556f106f97e1c67|./scripts/checkpatch.pl -
WARNING: Block comments use a leading /* on a separate line
#34: FILE: tests/libqtest.h:233:
+/**
The sequence "/\*\*?" was intended to match either "/*" or "/**",
but Perl's semantics for '?' allow it to backtrack and try the
"matches 0 chars" option if the "matches 1 char" choice leads to
a failure of the rest of the regex to match. Switch to "/\*\*?+"
which uses what perlre(1) calls the "possessive" quantifier form:
this means that if it matches the "/**" string it will not later
backtrack to matching just the "/*" prefix.
The other end of the regex is also wrong: it is attempting
to check for "/* or /** followed by something that isn't
just whitespace", but [ \t]*.+[ \t]* will match on pure
whitespace. This is less significant but means that a line
with just a comment-starter followed by trailing whitespace
will generate an incorrect warning about block comment style
as well as the correct error about trailing whitespace which
a different checkpatch test emits.
Reported-by: Thomas Huth <thuth@redhat.com>
Reported-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
This comment check is unique to QEMU checkpatch so the bugs
don't exist in the Linux version.
v1->v2 changes: Add the fix to the other end of the regex
pointed out by Eric, so that we don't emit spurious warnings
for block comment starters with trailing whitespace.
---
scripts/checkpatch.pl | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index d10dddf1be4..88682cb0a9f 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -1624,7 +1624,7 @@ sub process {
# Block comments use /* on a line of its own
if ($rawline !~ m@^\+.*/\*.*\*/[ \t]*$@ && #inline /*...*/
- $rawline =~ m@^\+.*/\*\*?[ \t]*.+[ \t]*$@) { # /* or /** non-blank
+ $rawline =~ m@^\+.*/\*\*?+[ \t]*[^ \t]@) { # /* or /** non-blank
WARN("Block comments use a leading /* on a separate line\n" . $herecurr);
}
--
2.20.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [Qemu-devel] [PATCH v2] checkpatch: Don't emit spurious warnings about block comments
2019-01-18 16:50 [Qemu-devel] [PATCH v2] checkpatch: Don't emit spurious warnings about block comments Peter Maydell
@ 2019-01-18 17:06 ` Eric Blake
2019-01-24 14:04 ` Peter Maydell
0 siblings, 1 reply; 3+ messages in thread
From: Eric Blake @ 2019-01-18 17:06 UTC (permalink / raw)
To: Peter Maydell, qemu-devel; +Cc: patches, Thomas Huth
[-- Attachment #1: Type: text/plain, Size: 2107 bytes --]
On 1/18/19 10:50 AM, Peter Maydell wrote:
> In checkpatch we attempt to check for and warn about
> block comments which start with /* or /** followed by a
> non-blank. Unfortunately a bug in the regex meant that
> we would incorrectly warn about comments starting with
> "/**" with no following text:
>
> git show 9813dc6ac3954d58ba16b3920556f106f97e1c67|./scripts/checkpatch.pl -
> WARNING: Block comments use a leading /* on a separate line
> #34: FILE: tests/libqtest.h:233:
> +/**
>
> The sequence "/\*\*?" was intended to match either "/*" or "/**",
> but Perl's semantics for '?' allow it to backtrack and try the
> "matches 0 chars" option if the "matches 1 char" choice leads to
> a failure of the rest of the regex to match. Switch to "/\*\*?+"
> which uses what perlre(1) calls the "possessive" quantifier form:
> this means that if it matches the "/**" string it will not later
> backtrack to matching just the "/*" prefix.
>
> The other end of the regex is also wrong: it is attempting
> to check for "/* or /** followed by something that isn't
> just whitespace", but [ \t]*.+[ \t]* will match on pure
> whitespace. This is less significant but means that a line
> with just a comment-starter followed by trailing whitespace
> will generate an incorrect warning about block comment style
> as well as the correct error about trailing whitespace which
> a different checkpatch test emits.
>
Fixes: 8c06fbdf36bf4d4d486116200248730887a4d7d6
> Reported-by: Thomas Huth <thuth@redhat.com>
> Reported-by: Eric Blake <eblake@redhat.com>
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
> # Block comments use /* on a line of its own
> if ($rawline !~ m@^\+.*/\*.*\*/[ \t]*$@ && #inline /*...*/
> - $rawline =~ m@^\+.*/\*\*?[ \t]*.+[ \t]*$@) { # /* or /** non-blank
> + $rawline =~ m@^\+.*/\*\*?+[ \t]*[^ \t]@) { # /* or /** non-blank
Reviewed-by: Eric Blake <eblake@redhat.com>
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3226
Virtualization: qemu.org | libvirt.org
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Qemu-devel] [PATCH v2] checkpatch: Don't emit spurious warnings about block comments
2019-01-18 17:06 ` Eric Blake
@ 2019-01-24 14:04 ` Peter Maydell
0 siblings, 0 replies; 3+ messages in thread
From: Peter Maydell @ 2019-01-24 14:04 UTC (permalink / raw)
To: Eric Blake; +Cc: QEMU Developers, patches, Thomas Huth
On Fri, 18 Jan 2019 at 17:06, Eric Blake <eblake@redhat.com> wrote:
>
> On 1/18/19 10:50 AM, Peter Maydell wrote:
> > In checkpatch we attempt to check for and warn about
> > block comments which start with /* or /** followed by a
> > non-blank. Unfortunately a bug in the regex meant that
> > we would incorrectly warn about comments starting with
> > "/**" with no following text:
> >
> > git show 9813dc6ac3954d58ba16b3920556f106f97e1c67|./scripts/checkpatch.pl -
> > WARNING: Block comments use a leading /* on a separate line
> > #34: FILE: tests/libqtest.h:233:
> > +/**
> >
> > The sequence "/\*\*?" was intended to match either "/*" or "/**",
> > but Perl's semantics for '?' allow it to backtrack and try the
> > "matches 0 chars" option if the "matches 1 char" choice leads to
> > a failure of the rest of the regex to match. Switch to "/\*\*?+"
> > which uses what perlre(1) calls the "possessive" quantifier form:
> > this means that if it matches the "/**" string it will not later
> > backtrack to matching just the "/*" prefix.
> >
> > The other end of the regex is also wrong: it is attempting
> > to check for "/* or /** followed by something that isn't
> > just whitespace", but [ \t]*.+[ \t]* will match on pure
> > whitespace. This is less significant but means that a line
> > with just a comment-starter followed by trailing whitespace
> > will generate an incorrect warning about block comment style
> > as well as the correct error about trailing whitespace which
> > a different checkpatch test emits.
> >
>
> Fixes: 8c06fbdf36bf4d4d486116200248730887a4d7d6
>
> > Reported-by: Thomas Huth <thuth@redhat.com>
> > Reported-by: Eric Blake <eblake@redhat.com>
> > Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> > ---
>
> > # Block comments use /* on a line of its own
> > if ($rawline !~ m@^\+.*/\*.*\*/[ \t]*$@ && #inline /*...*/
> > - $rawline =~ m@^\+.*/\*\*?[ \t]*.+[ \t]*$@) { # /* or /** non-blank
> > + $rawline =~ m@^\+.*/\*\*?+[ \t]*[^ \t]@) { # /* or /** non-blank
>
> Reviewed-by: Eric Blake <eblake@redhat.com>
Thanks. I'll take this via target-arm.next, just for convenience...
-- PMM
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-01-24 14:04 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-18 16:50 [Qemu-devel] [PATCH v2] checkpatch: Don't emit spurious warnings about block comments Peter Maydell
2019-01-18 17:06 ` Eric Blake
2019-01-24 14:04 ` Peter Maydell
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.