scripts/checksrc.pl: detect duplicated include files

After an idea by Dan Fandrich in #9794

Closes #9796
This commit is contained in:
Daniel Stenberg 2022-10-24 23:26:56 +02:00
parent 6092eaa3e6
commit 3678336b20
No known key found for this signature in database
GPG Key ID: 5CC908FDB71E12C2

View File

@ -380,6 +380,7 @@ sub scanfile {
my $incomment=0;
my @copyright=();
my %includes;
checksrc_clear(); # for file based ignores
accept_violations();
@ -472,6 +473,15 @@ sub scanfile {
$line, length($1), $file, $l, "\/\/ comment");
}
if($l =~ /^(\#\s*include\s+)([\">].*[>}"])/) {
my ($pre, $path) = ($1, $2);
if($includes{$path}) {
checkwarn("INCLUDEDUP",
$line, length($1), $file, $l, "duplicated include");
}
$includes{$path} = $l;
}
# detect and strip preprocessor directives
if($l =~ /^[ \t]*\#/) {
# preprocessor line