mirror of
https://github.com/curl/curl.git
synced 2025-09-17 17:42:49 +03:00
checksrc: ban snprintf use, add command line flag to override warns
This commit is contained in:
parent
dcd6f81025
commit
2e49610853
|
@ -35,6 +35,7 @@ my $suppressed; # whitelisted problems
|
||||||
my $file;
|
my $file;
|
||||||
my $dir=".";
|
my $dir=".";
|
||||||
my $wlist="";
|
my $wlist="";
|
||||||
|
my @alist;
|
||||||
my $windows_os = $^O eq 'MSWin32' || $^O eq 'msys' || $^O eq 'cygwin';
|
my $windows_os = $^O eq 'MSWin32' || $^O eq 'msys' || $^O eq 'cygwin';
|
||||||
my $verbose;
|
my $verbose;
|
||||||
my %whitelist;
|
my %whitelist;
|
||||||
|
@ -74,6 +75,7 @@ my %warnings = (
|
||||||
'SEMINOSPACE' => 'semicolon without following space',
|
'SEMINOSPACE' => 'semicolon without following space',
|
||||||
'MULTISPACE' => 'multiple spaces used when not suitable',
|
'MULTISPACE' => 'multiple spaces used when not suitable',
|
||||||
'SIZEOFNOPAREN' => 'use of sizeof without parentheses',
|
'SIZEOFNOPAREN' => 'use of sizeof without parentheses',
|
||||||
|
'SNPRINTF' => 'use of snprintf',
|
||||||
);
|
);
|
||||||
|
|
||||||
sub readwhitelist {
|
sub readwhitelist {
|
||||||
|
@ -153,6 +155,11 @@ while(1) {
|
||||||
$file = shift @ARGV;
|
$file = shift @ARGV;
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
|
elsif($file =~ /-A(.+)/) {
|
||||||
|
push @alist, $1;
|
||||||
|
$file = shift @ARGV;
|
||||||
|
next;
|
||||||
|
}
|
||||||
elsif($file =~ /-i([1-9])/) {
|
elsif($file =~ /-i([1-9])/) {
|
||||||
$indent = $1 + 0;
|
$indent = $1 + 0;
|
||||||
$file = shift @ARGV;
|
$file = shift @ARGV;
|
||||||
|
@ -174,6 +181,7 @@ while(1) {
|
||||||
if(!$file) {
|
if(!$file) {
|
||||||
print "checksrc.pl [option] <file1> [file2] ...\n";
|
print "checksrc.pl [option] <file1> [file2] ...\n";
|
||||||
print " Options:\n";
|
print " Options:\n";
|
||||||
|
print " -A[rule] Accept this violation, can be used multiple times\n";
|
||||||
print " -D[DIR] Directory to prepend file names\n";
|
print " -D[DIR] Directory to prepend file names\n";
|
||||||
print " -h Show help output\n";
|
print " -h Show help output\n";
|
||||||
print " -W[file] Whitelist the given file - ignore all its flaws\n";
|
print " -W[file] Whitelist the given file - ignore all its flaws\n";
|
||||||
|
@ -198,6 +206,17 @@ do {
|
||||||
|
|
||||||
} while($file);
|
} while($file);
|
||||||
|
|
||||||
|
sub accept_violations {
|
||||||
|
for my $r (@alist) {
|
||||||
|
if(!$warnings{$r}) {
|
||||||
|
print "'$r' is not a warning to accept!\n";
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$ignore{$r}=999999;
|
||||||
|
$ignore_used{$r}=0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
sub checksrc_clear {
|
sub checksrc_clear {
|
||||||
undef %ignore;
|
undef %ignore;
|
||||||
undef %ignore_set;
|
undef %ignore_set;
|
||||||
|
@ -297,6 +316,7 @@ sub scanfile {
|
||||||
my $incomment=0;
|
my $incomment=0;
|
||||||
my $copyright=0;
|
my $copyright=0;
|
||||||
checksrc_clear(); # for file based ignores
|
checksrc_clear(); # for file based ignores
|
||||||
|
accept_violations();
|
||||||
|
|
||||||
while(<R>) {
|
while(<R>) {
|
||||||
$windows_os ? $_ =~ s/\r?\n$// : chomp;
|
$windows_os ? $_ =~ s/\r?\n$// : chomp;
|
||||||
|
@ -511,6 +531,13 @@ sub scanfile {
|
||||||
"use of $2 is banned");
|
"use of $2 is banned");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# scan for use of snprintf for curl-internals reasons
|
||||||
|
if($l =~ /^(.*\W)(v?snprintf)\s*\(/x) {
|
||||||
|
checkwarn("SNPRINTF",
|
||||||
|
$line, length($1), $file, $ol,
|
||||||
|
"use of $2 is banned");
|
||||||
|
}
|
||||||
|
|
||||||
# scan for use of non-binary fopen without the macro
|
# scan for use of non-binary fopen without the macro
|
||||||
if($l =~ /^(.*\W)fopen\s*\([^,]*, *\"([^"]*)/) {
|
if($l =~ /^(.*\W)fopen\s*\([^,]*, *\"([^"]*)/) {
|
||||||
my $mode = $2;
|
my $mode = $2;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user