]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
checkpatch.pl: check for function declarations without arguments
authorJoe Perches <joe@perches.com>
Wed, 15 Jan 2014 05:56:09 +0000 (16:56 +1100)
committerStephen Rothwell <sfr@canb.auug.org.au>
Thu, 16 Jan 2014 05:54:01 +0000 (16:54 +1100)
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>
scripts/checkpatch.pl

index 05c99c0b7e6c8e272f374c05f3fa86804efaa5ed..be53ba79e09fa457bbd48e7618c084d35d9ed1be 100755 (executable)
@@ -2665,6 +2665,15 @@ sub process {
                                $herecurr);
                }
 
+# check for function declarations without arguments like "int foo()"
+               if ($line =~ /(\b$Type\s+$Ident)\s*\(\s*\)/) {
+                       if (ERROR("FUNCTION_WITHOUT_ARGS",
+                                 "Bad function definition - $1() should probably be $1(void)\n" . $herecurr) &&
+                           $fix) {
+                               $fixed[$linenr - 1] =~ s/(\b($Type)\s+($Ident))\s*\(\s*\)/$2 $3(void)/;
+                       }
+               }
+
 # check for uses of DEFINE_PCI_DEVICE_TABLE
                if ($line =~ /\bDEFINE_PCI_DEVICE_TABLE\s*\(\s*(\w+)\s*\)\s*=/) {
                        if (WARN("DEFINE_PCI_DEVICE_TABLE",