From c4b9173afdaad7a817d505b466ae27ee21325219 Mon Sep 17 00:00:00 2001 From: Johan Malm Date: Thu, 10 Aug 2023 15:48:52 +0100 Subject: [PATCH] checkpatch.pl: check single statement brace --- scripts/checkpatch.pl | 21 +++++++++++++++++++++ src/xwayland.c | 3 ++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 51bc0a26..30b31343 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -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*/) { diff --git a/src/xwayland.c b/src/xwayland.c index acbbbc07..2a67f0b6 100644 --- a/src/xwayland.c +++ b/src/xwayland.c @@ -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; }