Skip to contentSkip to conversation

checkpatch.pl: Check for functions without a real prototype

PATCH In review Elena Ufimtseva 2 participants 3 messages Nov 22, 2013 Checkpatch

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 checkpatch.pl: Check for functions without a real prototype

Based on Richard Weinberger patch https://lkml.org/lkml/2012/3/16/510
Functions like this one are evil:

void foo()

{
	...
}

---
Changes since v1:
- added white space in regular expression between (), based on comments from Joe Perches.

 scripts/checkpatch.pl |   13 +++++++++++++
 1 file changed, 13 insertions(+)
scripts/checkpatch.pl +13 -0
index 61090e0..08c95c0 100755
@@ -2785,6 +2785,19 @@ sub process {
 			      "open brace '{' following function declarations go on the next line\n" . $herecurr);
 		}
 
+		if ($line =~ /(\b$Type\s+$Ident)\s*\(\s*\)/) {
+			ERROR("FUNCTION_NO_PROTOTYPE",
+"Bad function definition - $1() should probably be $1(void)\n" . $herecurr .
+"\nThou shalt not, in the language of C, under any circumstances, on the
+pain of death, declare or define a function with an empty set of
+parentheses, for though in the language of C++ it meaneth the same as
+(void), in C it meaneth (...) which is of meaningless as there be no
+anchor argument by which the types of the varadic arguments can be
+expressed, and which misleadeth the compiler into allowing unsavory code
+and in some cases generate really ugly stuff for varadic handling.
+							-hpa\n");
+		}
+
 # open braces for enum, union and struct go on the same line.
 		if ($line =~ /^.\s*{/ &&
 		    $prevline =~ /^.\s*(?:typedef\s+)?(enum|union|struct)(?:\s+$Ident)?\s*$/) {
Signature · 1 line
1.7.10.4
maintainer
#1 lore raw
Quoted 7 lines · Elena Ufimtseva

Based on Richard Weinberger patch https://lkml.org/lkml/2012/3/16/510
Functions like this one are evil:

void foo()

{
	...
}

[]

Quoted 2 lines

- added white space in regular expression between (), based on comments from Joe Perches.

Thanks Elena, but this is already applied in -next.

#2 lore raw
Quoted 8 lines · Joe Perches
Quoted 7 lines · Elena Ufimtseva

Based on Richard Weinberger patch https://lkml.org/lkml/2012/3/16/510
Functions like this one are evil:

void foo()

{
      ...
}
Quoted 7 lines

[]

Quoted 2 lines

- added white space in regular expression between (), based on comments from Joe Perches.

Thanks Elena, but this is already applied in -next.

No problem, thanks Joe )

Signature · 1 line
Elena