checkpatch.pl: check single statement brace

This commit is contained in:
Johan Malm 2023-08-10 15:48:52 +01:00 committed by Johan Malm
parent b149526d03
commit c4b9173afd
2 changed files with 23 additions and 1 deletions

21
scripts/checkpatch.pl vendored
View file

@ -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*/)
{

View 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;
}