]> git.mdlowis.com Git - proto/labwc.git/commitdiff
checkpatch.pl: check single statement brace
authorJohan Malm <jgm323@gmail.com>
Thu, 10 Aug 2023 14:48:52 +0000 (15:48 +0100)
committerJohan Malm <johanmalm@users.noreply.github.com>
Fri, 11 Aug 2023 20:54:52 +0000 (21:54 +0100)
scripts/checkpatch.pl
src/xwayland.c

index 51bc0a2698f214e83a5f8b2f21d3155141756524..30b3134372649afeb752092ed6b7a423a2025fca 100755 (executable)
@@ -5508,11 +5508,32 @@ sub process {
                                }
                        }
 
+
+                       # We need this for the labwc-custom check below. It
+                       # avoids false positives with do { } while (); etc.
+                       my $starts_with_if_while_etc = 0;
+                       if ($s =~ /^\+\s*(if|while|for|switch).*/) {
+                               $starts_with_if_while_etc = 1;
+                       }
+
                        # Find out what is on the end of the line after the
                        # conditional.
                        substr($s, 0, length($c), '');
                        $s =~ s/\n.*//g;
                        $s =~ s/$;//g;  # Remove any comments
+
+                       # Find if/while/for/switch without opening braces
+                       # because (as opposed to Linux coding style) we use
+                       # braces for single statement blocks.
+                       #
+                       # include/ssd-internal.h contains a macro that we can't
+                       # deal with, so ignore that
+                       #
+                       if ($starts_with_if_while_etc && !length($s)
+                                       && $filename ne "include/ssd-internal.h") {
+                               CHK("BRACES", "[labwc-custom] open brace { expected after if/while/for/switch - even with single statement blocks");
+                       }
+
                        if (length($c) && $s !~ /^\s*{?\s*\\*\s*$/ &&
                            $c !~ /}\s*while\s*/)
                        {
index acbbbc076fed2168733df79be8e3b577d23f35af..2a67f0b634c9b0a3d85d06a91f6a905d5b00f7e1 100644 (file)
@@ -16,8 +16,9 @@
 static int
 round_to_increment(int val, int base, int inc)
 {
-       if (base < 0 || inc <= 0)
+       if (base < 0 || inc <= 0) {
                return val;
+       }
        return base + (val - base + inc / 2) / inc * inc;
 }