Skip to contentSkip to conversation

checkpatch: remove false unbalanced braces warning

PATCH Applied Sven Eckelmann 2 participants 2 messages Feb 20, 2017 – Feb 21, 2017 Checkpatch

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 checkpatch: remove false unbalanced braces warning

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")
---
 scripts/checkpatch.pl | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
scripts/checkpatch.pl +2 -2
index ad5ea5c545b2..baa3c7be04ad 100755
@@ -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);
 		}
 
Signature · 1 line
2.11.0
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 5 lines · 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

Yeah, thanks. That's what I meant to do originally.

cheers, Joe

Quoted 28 lines

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")
---
 scripts/checkpatch.pl | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
scripts/checkpatch.pl +2 -2
index ad5ea5c545b2..baa3c7be04ad 100755
@@ -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);
 		}