* [PATCH v2] checkpatch: Fix regex for do without braces
@ 2021-06-27 18:49 Dwaipayan Ray
2021-06-28 7:52 ` Alejandro Colomar (man-pages)
0 siblings, 1 reply; 2+ messages in thread
From: Dwaipayan Ray @ 2021-06-27 18:49 UTC (permalink / raw)
To: joe, apw; +Cc: lukas.bulwahn, linux-kernel, Dwaipayan Ray, Alejandro Colomar
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>
---
Changes in v2:
- Check word boundary on both sides of do
scripts/checkpatch.pl | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 8d19beca3538..64036e7eff71 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 =~ /\bdo\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
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH v2] checkpatch: Fix regex for do without braces
2021-06-27 18:49 [PATCH v2] checkpatch: Fix regex for do without braces Dwaipayan Ray
@ 2021-06-28 7:52 ` Alejandro Colomar (man-pages)
0 siblings, 0 replies; 2+ messages in thread
From: Alejandro Colomar (man-pages) @ 2021-06-28 7:52 UTC (permalink / raw)
To: Dwaipayan Ray, joe, apw; +Cc: lukas.bulwahn, linux-kernel
On 6/27/21 8:49 PM, Dwaipayan Ray wrote:
> 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>
Reviewed-by: Alejandro Colomar <alx.manpages@gmail.com>
Tested-by: Alejandro Colomar <alx.manpages@gmail.com>
(is Acked-by/Reviewed-by implied by Tested-by?)
> ---
>
> Changes in v2:
> - Check word boundary on both sides of do
>
> scripts/checkpatch.pl | 8 +++++---
> 1 file changed, 5 insertions(+), 3 deletions(-)
>
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> index 8d19beca3538..64036e7eff71 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 ({).
s/context detect/context, detect/
> + if ($line =~ /\bdo\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*#/) {
>
--
Alejandro Colomar
Linux man-pages comaintainer; https://www.kernel.org/doc/man-pages/
http://www.alejandro-colomar.es/
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-06-28 7:52 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-27 18:49 [PATCH v2] checkpatch: Fix regex for do without braces Dwaipayan Ray
2021-06-28 7:52 ` Alejandro Colomar (man-pages)
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®