Skip to contentSkip to conversation

checkpatch: notice unbalanced else braces in a patch

PATCH New [email protected] 1 participant 1 message Feb 24, 2017 Checkpatch

lore
Share & tools
lore
#0 lore raw

PATCH 123/124 checkpatch: notice unbalanced else braces in a patch

From: Joe Perches <[email protected]>
Subject: checkpatch: notice unbalanced else braces in a patch

Patches that add or modify code like

	} else
		<foo>
or
	else {
		<bar>

where one branch appears to have a brace and the other branch does not have a brace should emit a --strict style message.

---

 scripts/checkpatch.pl |    6 ++++++
 1 file changed, 6 insertions(+)
scripts/checkpatch.pl renamed from scripts/checkpatch.pl~checkpatch-notice-unbalanced-else-braces-in-a-patch +6 -0
diff -puN scripts/checkpatch.pl~checkpatch-notice-unbalanced-else-braces-in-a-patch scripts/checkpatch.pl
@@ -5104,6 +5104,12 @@ sub process {
 			}
 		}
 
+# check for single line unbalanced braces
+		if ($sline =~ /.\s*\}\s*else\s*$/ ||
+		    $sline =~ /.\s*else\s*\{\s*$/) {
+			CHK("BRACES", "Unbalanced braces around else statement\n" . $herecurr);
+		}
+
 # check for unnecessary blank lines around braces
 		if (($line =~ /^.\s*}\s*$/ && $prevrawline =~ /^.\s*$/)) {
 			if (CHK("BRACES",

_