1
0
mirror of https://github.com/moparisthebest/curl synced 2024-12-23 08:38:49 -05:00

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>
This commit is contained in:
Daniel Gustafsson 2018-10-05 13:29:37 +02:00
parent 4c35f24ef4
commit b5d182d037

View File

@ -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 "*") {