aboutsummaryrefslogtreecommitdiffstats
path: root/lib/checksrc.pl
diff options
context:
space:
mode:
Diffstat (limited to 'lib/checksrc.pl')
-rwxr-xr-xlib/checksrc.pl41
1 files changed, 29 insertions, 12 deletions
diff --git a/lib/checksrc.pl b/lib/checksrc.pl
index b074f274..97b8f9e1 100755
--- a/lib/checksrc.pl
+++ b/lib/checksrc.pl
@@ -31,14 +31,14 @@ my $warnings = 0;
my $swarnings = 0;
my $errors = 0;
my $serrors = 0;
-my $suppressed; # whitelisted problems
+my $suppressed; # skipped problems
my $file;
my $dir=".";
my $wlist="";
my @alist;
my $windows_os = $^O eq 'MSWin32' || $^O eq 'cygwin' || $^O eq 'msys';
my $verbose;
-my %whitelist;
+my %skiplist;
my %ignore;
my %ignore_set;
@@ -81,14 +81,15 @@ my %warnings = (
'SIZEOFNOPAREN' => 'use of sizeof without parentheses',
'SNPRINTF' => 'use of snprintf',
'ONELINECONDITION' => 'conditional block on the same line as the if()',
+ 'TYPEDEFSTRUCT' => 'typedefed struct',
);
-sub readwhitelist {
- open(W, "<$dir/checksrc.whitelist") or return;
+sub readskiplist {
+ open(W, "<$dir/checksrc.skip") or return;
my @all=<W>;
for(@all) {
$windows_os ? $_ =~ s/\r?\n$// : chomp;
- $whitelist{$_}=1;
+ $skiplist{$_}=1;
}
close(W);
}
@@ -116,10 +117,19 @@ sub readlocalfile {
}
$warnings{$1} = $warnings_extended{$1};
}
+ elsif (/^\s*disable ([A-Z]+)$/) {
+ if(!defined($warnings{$1})) {
+ print STDERR "invalid warning specified in .checksrc: \"$1\"\n";
+ next;
+ }
+ # Accept-list
+ push @alist, $1;
+ }
else {
die "Invalid format in $dir/.checksrc on line $i\n";
}
}
+ close($rcfile);
}
sub checkwarn {
@@ -132,8 +142,8 @@ sub checkwarn {
# print STDERR "Dev! there's no description for $name!\n";
#}
- # checksrc.whitelist
- if($whitelist{$line}) {
+ # checksrc.skip
+ if($skiplist{$line}) {
$nowarn = 1;
}
# !checksrc! controlled
@@ -218,7 +228,7 @@ if(!$file) {
print " -A[rule] Accept this violation, can be used multiple times\n";
print " -D[DIR] Directory to prepend file names\n";
print " -h Show help output\n";
- print " -W[file] Whitelist the given file - ignore all its flaws\n";
+ print " -W[file] Skip the given file - ignore all its flaws\n";
print " -i<n> Indent spaces. Default: 2\n";
print " -m<n> Maximum line length. Default: 79\n";
print "\nDetects and warns for these problems:\n";
@@ -228,7 +238,7 @@ if(!$file) {
exit;
}
-readwhitelist();
+readskiplist();
readlocalfile();
do {
@@ -639,10 +649,10 @@ sub scanfile {
}
# check for 'char * name'
- if(($l =~ /(^.*(char|int|long|void|curl_slist|CURL|CURLM|CURLMsg|curl_httppost) *(\*+)) (\w+)/) && ($4 ne "const")) {
- checkwarn("ASTERISKNOSPACE",
+ if(($l =~ /(^.*(char|int|long|void|CURL|CURLM|CURLMsg|[cC]url_[A-Za-z_]+|struct [a-zA-Z_]+) *(\*+)) (\w+)/) && ($4 !~ /^(const|volatile)$/)) {
+ checkwarn("ASTERISKSPACE",
$line, length($1), $file, $ol,
- "no space after declarative asterisk");
+ "space after declarative asterisk");
}
# check for 'char*'
if(($l =~ /(^.*(char|int|long|void|curl_slist|CURL|CURLM|CURLMsg|curl_httppost|sockaddr_in|FILE)\*)/)) {
@@ -697,6 +707,13 @@ sub scanfile {
"no space after semicolon");
}
+ # typedef struct ... {
+ if($nostr =~ /^(.*)typedef struct.*{/) {
+ checkwarn("TYPEDEFSTRUCT",
+ $line, length($1)+1, $file, $ol,
+ "typedef'ed struct");
+ }
+
# check for more than one consecutive space before open brace or
# question mark. Skip lines containing strings since they make it hard
# due to artificially getting multiple spaces