summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Gustafsson <daniel@yesql.se>2018-10-05 13:29:37 +0200
committerDaniel Gustafsson <daniel@yesql.se>2018-10-05 13:29:37 +0200
commitb5d182d037364c5fff250f0ad48066c05115dc7f (patch)
tree1dfd03a9d87ae2ef1bfefd44a0c1f0d341ac51c2
parent4c35f24ef463a2124395a8a6eb2c23e3c568e067 (diff)
downloadcurl-b5d182d037364c5fff250f0ad48066c05115dc7f.tar.gz
checksrc: enable strict mode and warnings
Enable strict and warnings mode for checksrc to ensure we aren't missing anything due to bugs in the checking code. This uncovered a few things which are all fixed in this commit: * several variables were used uninitialized * several variables were not defined in the correct scope * the whitelist filehandle was read even if the file didn't exist * the enable_warn() call when a disable counter had expired was passing incorrect variables, but since the checkwarn() call is unlikely to hit (the counter is only decremented to zero on actual ignores) it didn't manifest a problem. Closes #3090 Reviewed-by: Daniel Stenberg <daniel@haxx.se> Reviewed-by: Marcel Raad <Marcel.Raad@teamviewer.com>
-rwxr-xr-xlib/checksrc.pl26
1 files changed, 18 insertions, 8 deletions
diff --git a/lib/checksrc.pl b/lib/checksrc.pl
index daff07bf5..1af6bbd72 100755
--- a/lib/checksrc.pl
+++ b/lib/checksrc.pl
@@ -21,19 +21,29 @@
#
###########################################################################
+use strict;
+use warnings;
+
my $max_column = 79;
my $indent = 2;
-my $warnings;
-my $errors;
+my $warnings = 0;
+my $swarnings = 0;
+my $errors = 0;
+my $serrors = 0;
my $suppressed; # whitelisted problems
my $file;
my $dir=".";
-my $wlist;
+my $wlist="";
my $windows_os = $^O eq 'MSWin32' || $^O eq 'msys' || $^O eq 'cygwin';
my $verbose;
my %whitelist;
+my %ignore;
+my %ignore_set;
+my %ignore_used;
+my @ignore_line;
+
my %warnings = (
'LONGLINE' => "Line longer than $max_column",
'TABS' => 'TAB characters not allowed',
@@ -67,7 +77,7 @@ my %warnings = (
);
sub readwhitelist {
- open(W, "<$dir/checksrc.whitelist");
+ open(W, "<$dir/checksrc.whitelist") or return;
my @all=<W>;
for(@all) {
$windows_os ? $_ =~ s/\r?\n$// : chomp;
@@ -97,7 +107,7 @@ sub checkwarn {
$nowarn = 1;
if(!$ignore{$name}) {
# reached zero, enable again
- enable_warn($name, $line, $file, $l);
+ enable_warn($name, $num, $file, $line);
}
}
@@ -271,7 +281,7 @@ sub scanfile {
my ($file) = @_;
my $line = 1;
- my $prevl;
+ my $prevl="";
my $l;
open(R, "<$file") || die "failed to open $file";
@@ -359,10 +369,10 @@ sub scanfile {
if($1 =~ / *\#/) {
# this is a #if, treat it differently
}
- elsif($3 eq "return") {
+ elsif(defined $3 && $3 eq "return") {
# return must have a space
}
- elsif($3 eq "case") {
+ elsif(defined $3 && $3 eq "case") {
# case must have a space
}
elsif($4 eq "*") {