checkpatch: Don't spuriously warn about /** comment starters
PATCH 1/1 checkpatch: Don't spuriously warn about /** comment starters
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.
---
This comment check is unique to QEMU checkpatch so the bug doesn't exist in the Linux version.
--- scripts/checkpatch.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/checkpatch.pl +1 -1
@@ -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); }
Signature · 1 line
2.20.1
Quoted 11 lines · Peter Maydell
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:
+/**
Quoted 7 lines
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.
Just wondering if "/\*{1,2}" would also work (it may have to be spelled "/\*\{1,2}" - I never remember which flavors of regex have which extensions without rereading docs). But since your way is tested, I'm not going to force a respin.
Quoted 15 lines
Reported-by Thomas Huth <[email protected]>Signed-off-by Peter Maydell <[email protected]>---
This comment check is unique to QEMU checkpatch so the bug doesn't exist in the Linux version.--- scripts/checkpatch.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)scripts/checkpatch.pl +0
-0
scripts/checkpatch.pl sub process { · line 1627
Quoted 5 lines
scripts/checkpatch.pl +1
-1@@ -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
Hmm - Isn't "[ \t]*.+[ \t]*$" the same as ".+$?" Perhaps:
m@^\+.*/\*([^*]|\*.)@
also does the trick in a more legible way (that is, any line that starts with /* and then contains any additional characters other than a second *)?
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
Quoted 21 lines · Eric Blake
Quoted 11 lines · Peter Maydell
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:
+/**Quoted 7 lines
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.
Quoted 3 lines
Just wondering if "/\*{1,2}" would also work (it may have to be spelled "/\*\{1,2}" - I never remember which flavors of regex have which extensions without rereading docs)
Oh yes, that would probably be the less perl-specific way to write it.
Perl regexes have the convenient property that backslash followed by a punctuation character always means "that character literally", whether or not that punctuation character has a metacharacter meaning when not escaped. So it's definitely the non-backslash version. (As an aside, it's a bit sad that Rust regexes don't have this property.)
Quoted 12 lines
Quoted 12 lines
This comment check is unique to QEMU checkpatch so the bug doesn't exist in the Linux version.
--- scripts/checkpatch.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)scripts/checkpatch.pl +0
-0@@ -1624,7 +1624,7 @@ sub process {
Quoted 6 lines
scripts/checkpatch.pl sub process { · line 1627
Quoted 4 lines
scripts/checkpatch.pl +1
-1# 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-blankHmm - Isn't "[ \t]*.+[ \t]*$" the same as ".+$?"
(do you mean '$?"' at the end of your sentence, or '$" ?' ?)
I'm not sure exactly what I was aiming for with that part of the regex when I wrote it. The comment suggests that I was looking for "non-blank", ie I didn't want to fire on /* or /** followed by just trailing whitespace. The regex as written is clearly not actually doing that, though...
-- PMM
Quoted 8 lines · Peter Maydell
Quoted 8 lines
Quoted 7 lines
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.
Quoted 6 lines
Quoted 3 lines
Just wondering if "/\*{1,2}" would also work (it may have to be spelled "/\*\{1,2}" - I never remember which flavors of regex have which extensions without rereading docs)
Oh yes, that would probably be the less perl-specific way to write it.
Except it would probably fail in the same way as the non-greedy \*? - when \*{2} can't satisfy the regex, the engine will retry with \*{1} and then see the second * as noise.
Quoted 8 lines
Quoted 6 lines
scripts/checkpatch.pl sub process { · line 1627
Quoted 4 lines
# Block comments use /* on a line of its own
if ($rawline !~ m@^\+.*/\*.*\*/[ \t]*$@ && #inline /*...*/scripts/checkpatch.pl +1
-1- $rawline =~ m@^\+.*/\*\*?[ \t]*.+[ \t]*$@) { # /* or /** non-blank + $rawline =~ m@^\+.*/\*\*?+[ \t]*.+[ \t]*$@) { # /* or /** non-blankHmm - Isn't "[ \t]*.+[ \t]*$" the same as ".+$?"
(do you mean '$?"' at the end of your sentence, or '$" ?' ?)
Serves me right for adding "" after the fact. You are correct, intended punctuation should be ".+$"? (the 3-character regex, concluded by asking a question if the 3-character form is the same as the 15-character form), and where I should have gone further and asked if it was the same as "." (since who cares whether there are more than one extra characters between there and the end of the line - once we've found any character at all, we've already found enough to flag the line).
Quoted 7 lines
I'm not sure exactly what I was aiming for with that part of the regex when I wrote it. The comment suggests that I was looking for "non-blank", ie I didn't want to fire on /* or /** followed by just trailing whitespace. The regex as written is clearly not actually doing that, though...
Trailing whitespace is generally a problem anyways, though :)
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
Quoted 15 lines · Eric Blake
Quoted 12 lines · Peter Maydell
Quoted 11 lines
Quoted 7 lines
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.Just wondering if "/\*{1,2}" would also work (it may have to be spelled "/\*\{1,2}" - I never remember which flavors of regex have which extensions without rereading docs)
Quoted 6 lines
Quoted 2 lines
Oh yes, that would probably be the less perl-specific way to write it.
Except it would probably fail in the same way as the non-greedy \*? - when \*{2} can't satisfy the regex, the engine will retry with \*{1} and then see the second * as noise.
OK, so the patch is good as it is, though it doesn't address the possible incorrect warnings with trailing whitespace.
Quoted 8 lines
Quoted 6 lines
I'm not sure exactly what I was aiming for with that part of the regex when I wrote it. The comment suggests that I was looking for "non-blank", ie I didn't want to fire on /* or /** followed by just trailing whitespace. The regex as written is clearly not actually doing that, though...
Trailing whitespace is generally a problem anyways, though :)
Yes, but checkpatch already checks for that, so we don't want to report an incorrect "wrong blockquote" warning as well as the "trailing whitespace" error, which is what the current code does:
ERROR: trailing whitespace
#159: FILE: hw/arm/mps2-tz.c:391:
+ /* $
WARNING: Block comments use a leading /* on a separate line #159: FILE: hw/arm/mps2-tz.c:391:
+ /*
total: 1 errors, 1 warnings, 165 lines checked
thanks
-- PMM