Skip to contentSkip to conversation

Make checkpatch rant about trailing ; at the end of "if" expr

PATCH In review Eugene Teo 3 participants 3 messages Aug 16, 2007 – Aug 17, 2007

lore
Share & tools
lore

Eugene Teo

author
#0 lore raw

PATCH 1/1 Make checkpatch rant about trailing ; at the end of "if" expr

Make checkpatch rant about trailing ; at the end of "if" expression.

Thanks to Auke for the regexp.

Signed-off by: Eugene Teo <[email protected]>

checkpatch.pl-0.09 renamed from checkpatch.pl-0.09.default +6 -0
@@ -1091,6 +1091,12 @@ sub process {
 				CHK("__setup appears un-documented -- check Documentation/kernel-parameters.txt\n" . $herecurr);
 			}
 		}
+
+# checks for trailing ; at the end of "if" expression
+		if ($line =~ /\bif\s*\([^\)]*\)\s*\;/) {
+			my $herevet = "$here\n" . cat_vet($line) . "\n";
+			ERROR("trailing ;\n" . $herevet);
+		}
 	}
 
 	if ($chk_patch && !$is_patch) {
#1 lore raw
Quoted 11 lines · Eugene Teo

Make checkpatch rant about trailing ; at the end of "if" expression.

Thanks to Auke for the regexp.

Signed-off by: Eugene Teo <[email protected]>

checkpatch.pl-0.09 renamed from checkpatch.pl-0.09.default +0 -0
@@ -1091,6 +1091,12 @@ sub process {
 				CHK("__setup appears un-documented -- check Documentation/kernel-parameters.txt\n" . $herecurr);
 			}

checkpatch.pl-0.09 sub process { · line 1102

Quoted 10 lines
checkpatch.pl-0.09 renamed from checkpatch.pl-0.09.default +6 -0
 		}
+
+# checks for trailing ; at the end of "if" expression
+		if ($line =~ /\bif\s*\([^\)]*\)\s*\;/) {
+			my $herevet = "$here\n" . cat_vet($line) . "\n";
+			ERROR("trailing ;\n" . $herevet);
+		}
 	}
 
 	if ($chk_patch && !$is_patch) {

Heh, you are the second person to suggest this check today, do I detect some ripped out hair due to one of these!

I've taken this idea and expanded it to cover if, for and while which can all suffer from this. Using the relative indent to work out which are valid combinations:

WARNING: Trailing semicolon indicates no statements, indent implies otherwise
#28: FILE: Z17.c:25:
+ if (foo);
+ return 10;
WARNING: Trailing semicolon indicates no statements, indent implies otherwise
#31: FILE: Z17.c:28:
+ for (a; b; c);
+ a += *b;

Thanks for the patch.

-apw

#2 lore raw
Quoted 8 lines · Andy Whitcroft

checkpatch.pl-0.09 sub process { · line 1096

Quoted 1 line
checkpatch.pl-0.09 renamed from checkpatch.pl-0.09.default +1 -0
+		if ($line =~ /\bif\s*\([^\)]*\)\s*\;/) {

Heh, you are the second person to suggest this check today, do I detect some ripped out hair due to one of these!

I've taken this idea and expanded it to cover if, for and while which can all suffer from this. Using the relative indent to work out which are valid combinations:

But. The above regex does not seem to handle

	if ((a = b));
		oops;

I have tried to come up with a superduper regex that handles multiple (), but my regex fu seems to stop above two pairs of ().

#!/usr/bin/perl

@check = (

	q"if ((ptr = malloc(bong, GFP)) == NULL)  ; (oopsie) ;",
	q"if ((ptr = malloc(bong, GFP)) == NULL)    (alright);",
	q"if (  ({ bool evil = (true); evil; }) ) ; (oopsie) ;",
	q"if (  ({ bool evil = (true); evil; }) )   (alright);",
	q"if((()));",

);

my $r = qr/\s*\(\s*(??{$r})?\s*\)\s*|\s*\(\s*[^()]+\s*\)\s*/;

foreach (@check) {
	if ($_ =~ /(if|for|while)$r;/) {
		print "ok $_\n";
	}
}

Jan