]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
singleuse: add scan for use in other source codes
authorDaniel Stenberg <daniel@haxx.se>
Mon, 25 Sep 2023 07:42:12 +0000 (09:42 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Mon, 25 Sep 2023 15:05:49 +0000 (17:05 +0200)
This should reduce false-positive to almost zero. Checks for presence in
unit tests if --unit is specified, which is intended for debug builds
where unit testing is enabled.

Closes #11932

scripts/singleuse.pl

index 48dd3387fb96a2a7f16a0a3dfb8bcbae18c71ed3..7b0b099647037593c545594b1dabf89d804ec1db 100755 (executable)
 #
 # Use it like this:
 #
-# $ ./scripts/singleuse.pl lib/.libs/libcurl.a
+# $ ./scripts/singleuse.pl [--unit] lib/.libs/libcurl.a
 #
-# Be aware that it might cause false positives due to various build options.
+# --unit : built to support unit tests
 #
 
+my $unittests;
+if($ARGV[0] eq "--unit") {
+    $unittests = "tests/unit ";
+    shift @ARGV;
+}
+
 my $file = $ARGV[0];
 
 my %wl = (
-    'Curl_none_cert_status_request' => 'multiple TLS backends',
-    'Curl_none_check_cxn' => 'multiple TLS backends',
-    'Curl_none_cleanup' => 'multiple TLS backends',
-    'Curl_none_close_all' => 'multiple TLS backends',
-    'Curl_none_data_pending' => 'multiple TLS backends',
-    'Curl_none_engines_list' => 'multiple TLS backends',
-    'Curl_none_init' => 'multiple TLS backends',
-    'Curl_none_md5sum' => 'multiple TLS backends',
-    'Curl_none_random' => 'multiple TLS backends',
-    'Curl_none_session_free' => 'multiple TLS backends',
-    'Curl_none_set_engine' => 'multiple TLS backends',
-    'Curl_none_set_engine_default' => 'multiple TLS backends',
-    'Curl_none_shutdown' => 'multiple TLS backends',
-    'Curl_multi_dump' => 'debug build only',
-    'Curl_parse_port' => 'UNITTEST',
-    'Curl_shuffle_addr' => 'UNITTEST',
-    'de_cleanup' => 'UNITTEST',
-    'doh_decode' => 'UNITTEST',
-    'doh_encode' => 'UNITTEST',
-    'Curl_auth_digest_get_pair' => 'by digest_sspi',
     'curlx_uztoso' => 'cmdline tool use',
-    'curlx_uztoul' => 'by krb5_sspi',
-    'curlx_uitous' => 'by schannel',
-    'Curl_islower' => 'by curl_fnmatch',
-    'getaddressinfo' => 'UNITTEST',
     );
 
 my %api = (
@@ -161,6 +143,23 @@ my %api = (
     'curl_easy_perform_ev' => 'debug-build',
     );
 
+sub doublecheck {
+    my ($f, $used) = @_;
+    open(F, "git grep -le '$f\\W' -- lib ${unittests}packages|");
+    my @also;
+    while(<F>) {
+        my $e = $_;
+        chomp $e;
+        if($e =~ /\.[c]$/) {
+            if($e !~ /^lib\/${used}\.c/) {
+                push @also, $e;
+            }
+        }
+    }
+    close(F);
+    return @also;
+}
+
 open(N, "nm $file|") ||
     die;
 
@@ -207,8 +206,15 @@ for(sort keys %exist) {
             #print "$_ is WL\n";
         }
         else {
-            printf "%s is defined in %s, but not used outside\n", $_, $exist{$_};
-            $err++;
+            my $c = $_;
+            my @also = doublecheck($c, $exist{$c});
+            if(!scalar(@also)) {
+                printf "%s in %s\n", $c, $exist{$c};
+                $err++;
+            }
+            #    foreach my $a (@also) {
+            #        print "  $a\n";
+            #    }
         }
     }
     elsif($_ =~ /^curl_/) {