CHECKPATCH: Add warning for single else statement.
authorDon Slutz <Don@CloudSwitch.com>
Sun, 2 Sep 2012 23:22:38 +0000 (19:22 -0400)
committerBlue Swirl <blauwirbel@gmail.com>
Wed, 5 Sep 2012 19:17:49 +0000 (19:17 +0000)
For an example:

WARNING: braces {} are necessary even for single statement blocks
+    } else
+        return env->regs[R_EAX];

total: 0 errors, 1 warnings, 41 lines checked
Signed-off-by: Don Slutz <Don@CloudSwitch.com>
Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
scripts/checkpatch.pl

index 7ec8846..ec0aa4c 100755 (executable)
@@ -2547,12 +2547,16 @@ sub process {
                                        $line !~ /\#\s*else/) {
                        my $allowed = 0;
 
-                       # Check the pre-context.
-                       if (substr($line, 0, $-[0]) =~ /(\}\s*)$/) {
-                            print "APW: ALLOWED: pre<$pre> line<$line>\n"
-                                if $dbg_adv_apw;
-                            $allowed = 1;
-                       }
+                        # Check the pre-context.
+                        if (substr($line, 0, $-[0]) =~ /(\}\s*)$/) {
+                            my $pre = $1;
+
+                            if ($line !~ /else/) {
+                                print "APW: ALLOWED: pre<$pre> line<$line>\n"
+                                    if $dbg_adv_apw;
+                                $allowed = 1;
+                            }
+                        }
 
                        my ($level, $endln, @chunks) =
                                ctx_statement_full($linenr, $realcnt, $-[0]);