checkpatch: Fix regex for do without braces
PATCH v2 1/1 checkpatch: Fix regex for do without braces
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.
---
Changes in v2:
- Check word boundary on both sides of do
scripts/checkpatch.pl | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
scripts/checkpatch.pl +5 -3
@@ -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*#/) {
Signature · 1 line
2.28.0
Quoted 10 lines · Dwaipayan Ray
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 <[email protected]>Signed-off-by Dwaipayan Ray <[email protected]>
(is Acked-by/Reviewed-by implied by Tested-by?)
Quoted 13 lines
---
Changes in v2:
- Check word boundary on both sides of doscripts/checkpatch.pl | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)scripts/checkpatch.pl +0
-0
scripts/checkpatch.pl sub process { · line 5491
Quoted 7 lines
scripts/checkpatch.pl +1
-3@@ -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/
Quoted 15 lines
scripts/checkpatch.pl +4
-0+ 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*#/) {
Signature · 3 lines
Alejandro Colomar Linux man-pages comaintainer; https://www.kernel.org/doc/man-pages/ http://www.alejandro-colomar.es/