]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
scripts/checksrc.pl: detect duplicated include files
authorDaniel Stenberg <daniel@haxx.se>
Mon, 24 Oct 2022 21:26:56 +0000 (23:26 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Wed, 26 Oct 2022 09:27:29 +0000 (11:27 +0200)
After an idea by Dan Fandrich in #9794

Closes #9796

scripts/checksrc.pl

index 651b4b7007ddc258d9e84da997347c352b44e4aa..54cd30cd973e27eee075a0420a913425f284371f 100755 (executable)
@@ -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