From b5d182d037364c5fff250f0ad48066c05115dc7f Mon Sep 17 00:00:00 2001 From: Daniel Gustafsson Date: Fri, 5 Oct 2018 13:29:37 +0200 Subject: 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 Reviewed-by: Marcel Raad --- lib/checksrc.pl | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) (limited to 'lib') 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=; 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 "*") { -- cgit v1.2.3