summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorPaul Dagnelie <[email protected]>2017-01-18 01:47:50 +0300
committerBrian Behlendorf <[email protected]>2017-01-22 13:25:40 -0800
commitec441a9c534815b379468a2d349011cbd5bcd884 (patch)
treee44b1ac8c176d0a130af1791c25fef7e7a54b77b /scripts
parentbb7ffdaf5ad1c7e65af598830957b6b19835f93f (diff)
OpenZFS 6459 - cstyle doesn't detect opening braces on the same line as function header
Authored by: Paul Dagnelie <[email protected]> Reviewed by: Matthew Ahrens <[email protected]> Reviewed by: Alex Reece <[email protected]> Reviewed by: Albert Lee <[email protected]> Reviewed by: Dan McDonald <[email protected]> Approved by: Robert Mustacchi <[email protected]> Ported-by: George Melikov [email protected] OpenZFS-issue: https://www.illumos.org/issues/6459 OpenZFS-commit: https://github.com/openzfs/openzfs/commit/c4567a6 Porting notes: These changes are adopted for ZoL codebase because of many false positive warnings.
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/cstyle.pl50
1 files changed, 49 insertions, 1 deletions
diff --git a/scripts/cstyle.pl b/scripts/cstyle.pl
index 015a6fb09..7b0c9b7e7 100755
--- a/scripts/cstyle.pl
+++ b/scripts/cstyle.pl
@@ -240,6 +240,7 @@ my $comment_done = 0;
my $in_warlock_comment = 0;
my $in_function = 0;
my $in_function_header = 0;
+my $function_header_full_indent = 0;
my $in_declaration = 0;
my $note_level = 0;
my $nextok = 0;
@@ -385,6 +386,7 @@ line: while (<$filehandle>) {
$in_function = 1;
$in_declaration = 1;
$in_function_header = 0;
+ $function_header_full_indent = 0;
$prev = $line;
next line;
}
@@ -397,8 +399,54 @@ line: while (<$filehandle>) {
$prev = $line;
next line;
}
- if (/^\w*\($/) {
+ if ($in_function_header && ! /^ ./ ) {
+ if (/^{}$/ # empty functions
+ || /;/ #run function with multiline arguments
+ || /#/ #preprocessor commands
+ || /^[^\s\\]*\(.*\)$/ #functions without ; at the end
+ || /^$/ #function declaration can't have empty line
+ ) {
+ $in_function_header = 0;
+ $function_header_full_indent = 0;
+ } elsif ($prev =~ /^__attribute__/) { #__attribute__((*))
+ $in_function_header = 0;
+ $function_header_full_indent = 0;
+ $prev = $line;
+ next line;
+ } elsif ($picky && ! (/^\t/ && $function_header_full_indent != 0)) {
+
+ err("continuation line should be indented by 4 spaces");
+ }
+ }
+
+ #
+ # If this matches something of form "foo(", it's probably a function
+ # definition, unless it ends with ") bar;", in which case it's a declaration
+ # that uses a macro to generate the type.
+ #
+ if (/^\w+\(/ && !/\) \w+;/) {
$in_function_header = 1;
+ if (/\($/) {
+ $function_header_full_indent = 1;
+ }
+ }
+ if ($in_function_header && /^{$/) {
+ $in_function_header = 0;
+ $function_header_full_indent = 0;
+ $in_function = 1;
+ }
+ if ($in_function_header && /\);$/) {
+ $in_function_header = 0;
+ $function_header_full_indent = 0;
+ }
+ if ($in_function_header && /{$/ ) {
+ if ($picky == 1) {
+ err("opening brace on same line as function header");
+ }
+ $in_function_header = 0;
+ $function_header_full_indent = 0;
+ $in_function = 1;
+ next line;
}
if ($in_warlock_comment && /\*\//) {