checkpatch: warn on #defines ending in semicolon
Using a #define ending in a semicolon is poor style and can lead to unexpected code paths being executed. Warn on uses of these #define types: #define foo[(...)] bar; #define foo[(...)] \ bar; Based on a patch from Borislav Petkov. Signed-off-by: Joe Perches <joe@perches.com> Cc: Borislav Petkov <bp@suse.de> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
parent
2ac73b4f68
commit
f5ef95b12e
|
@ -3821,6 +3821,17 @@ sub process {
|
||||||
WARN("DO_WHILE_MACRO_WITH_TRAILING_SEMICOLON",
|
WARN("DO_WHILE_MACRO_WITH_TRAILING_SEMICOLON",
|
||||||
"do {} while (0) macros should not be semicolon terminated\n" . "$herectx");
|
"do {} while (0) macros should not be semicolon terminated\n" . "$herectx");
|
||||||
}
|
}
|
||||||
|
} elsif ($dstat =~ /^\+\s*#\s*define\s+$Ident.*;\s*$/) {
|
||||||
|
$ctx =~ s/\n*$//;
|
||||||
|
my $cnt = statement_rawlines($ctx);
|
||||||
|
my $herectx = $here . "\n";
|
||||||
|
|
||||||
|
for (my $n = 0; $n < $cnt; $n++) {
|
||||||
|
$herectx .= raw_line($linenr, $n) . "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
WARN("TRAILING_SEMICOLON",
|
||||||
|
"macros should not use a trailing semicolon\n" . "$herectx");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue