* [PATCH] checkpatch: remove false unbalanced braces warning
@ 2017-02-20 12:16 Sven Eckelmann
2017-02-21 2:42 ` Joe Perches
0 siblings, 1 reply; 2+ messages in thread
From: Sven Eckelmann @ 2017-02-20 12:16 UTC (permalink / raw)
To: Joe Perches; +Cc: Andy Whitcroft, linux-kernel, Sven Eckelmann
Lines containing "} else {" should not be detected as unbalanced braces.
But the second check can be reduced to ".+else\s*{" and it therefore
never checked if the beginning of a line contains any other character
(like the relevant "}"). This check would also return true for
"} else {" and create warnings like
CHECK: Unbalanced braces around else statement
#391: FILE: ./net/batman-adv/tvlv.c:391:
+ } else {
The check can be changed to check the whole line for the missing "}" to
avoid this false positive.
Fixes: 0d1532456c26 ("checkpatch: notice unbalanced else braces in a patch")
Signed-off-by: Sven Eckelmann <sven@narfation.org>
---
scripts/checkpatch.pl | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index ad5ea5c545b2..baa3c7be04ad 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -5107,8 +5107,8 @@ sub process {
}
# check for single line unbalanced braces
- if ($sline =~ /.\s*\}\s*else\s*$/ ||
- $sline =~ /.\s*else\s*\{\s*$/) {
+ if ($sline =~ /^.\s*\}\s*else\s*$/ ||
+ $sline =~ /^.\s*else\s*\{\s*$/) {
CHK("BRACES", "Unbalanced braces around else statement\n" . $herecurr);
}
--
2.11.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] checkpatch: remove false unbalanced braces warning
2017-02-20 12:16 [PATCH] checkpatch: remove false unbalanced braces warning Sven Eckelmann
@ 2017-02-21 2:42 ` Joe Perches
0 siblings, 0 replies; 2+ messages in thread
From: Joe Perches @ 2017-02-21 2:42 UTC (permalink / raw)
To: Sven Eckelmann, Andrew Morton; +Cc: Andy Whitcroft, linux-kernel
On Mon, 2017-02-20 at 13:16 +0100, Sven Eckelmann wrote:
> Lines containing "} else {" should not be detected as unbalanced braces.
> But the second check can be reduced to ".+else\s*{" and it therefore
> never checked if the beginning of a line contains any other character
> (like the relevant "}"). This check would also return true for
> "} else {" and create warnings like
Yeah, thanks. That's what I meant to do originally.
Acked-by: Joe Perches <joe@perches.com>
cheers, Joe
> CHECK: Unbalanced braces around else statement
> #391: FILE: ./net/batman-adv/tvlv.c:391:
> + } else {
>
> The check can be changed to check the whole line for the missing "}" to
> avoid this false positive.
>
> Fixes: 0d1532456c26 ("checkpatch: notice unbalanced else braces in a patch")
> Signed-off-by: Sven Eckelmann <sven@narfation.org>
> ---
> scripts/checkpatch.pl | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> index ad5ea5c545b2..baa3c7be04ad 100755
> --- a/scripts/checkpatch.pl
> +++ b/scripts/checkpatch.pl
> @@ -5107,8 +5107,8 @@ sub process {
> }
>
> # check for single line unbalanced braces
> - if ($sline =~ /.\s*\}\s*else\s*$/ ||
> - $sline =~ /.\s*else\s*\{\s*$/) {
> + if ($sline =~ /^.\s*\}\s*else\s*$/ ||
> + $sline =~ /^.\s*else\s*\{\s*$/) {
> CHK("BRACES", "Unbalanced braces around else statement\n" . $herecurr);
> }
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2017-02-21 2:43 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-20 12:16 [PATCH] checkpatch: remove false unbalanced braces warning Sven Eckelmann
2017-02-21 2:42 ` Joe Perches
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.