Skip to content

Commit b36190c

Browse files
JoePerchestorvalds
authored andcommitted
checkpatch.pl: check for function declarations without arguments
Functions like this one are evil: void foo() { ... } Because these functions allow variadic arguments without checking the arguments at all. Original patch by Richard Weinberger. Signed-off-by: Joe Perches <joe@perches.com> Cc: Richard Weinberger <richard@nod.at> Cc: Borislav Petkov <bp@alien8.de> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent a3978a5 commit b36190c

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

‎scripts/checkpatch.pl‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2665,6 +2665,15 @@ sub process {
26652665
$herecurr);
26662666
}
26672667

2668+
# check for function declarations without arguments like "int foo()"
2669+
if ($line =~ /(\b$Type\s+$Ident)\s*\(\s*\)/) {
2670+
if (ERROR("FUNCTION_WITHOUT_ARGS",
2671+
"Bad function definition - $1() should probably be $1(void)\n" . $herecurr) &&
2672+
$fix) {
2673+
$fixed[$linenr - 1] =~ s/(\b($Type)\s+($Ident))\s*\(\s*\)/$2 $3(void)/;
2674+
}
2675+
}
2676+
26682677
# check for uses of DEFINE_PCI_DEVICE_TABLE
26692678
if ($line =~ /\bDEFINE_PCI_DEVICE_TABLE\s*\(\s*(\w+)\s*\)\s*=/) {
26702679
if (WARN("DEFINE_PCI_DEVICE_TABLE",

0 commit comments

Comments
 (0)