Messages in this thread Patch in this message | | | Subject | [PATCH] checkpatch: Warn on #defines ending in semicolon | From | Joe Perches <> | Date | Fri, 09 May 2014 14:31:46 -0700 |
| |
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;
Original-patch-by: Borislav Petkov <bp@suse.de> Signed-off-by: Joe Perches <joe@perches.com> --- scripts/checkpatch.pl | 11 +++++++++++ 1 file changed, 11 insertions(+)
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 34eb216..3b5651a 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -3782,6 +3782,17 @@ sub process { WARN("DO_WHILE_MACRO_WITH_TRAILING_SEMICOLON", "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"); } }
| |