]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
wireshark-pidl: Don't warn about unused hfs used in CODE blocks
authorJohn Thacker <johnthacker@gmail.com>
Sun, 12 Oct 2025 19:18:11 +0000 (15:18 -0400)
committerAndreas Schneider <asn@cryptomilk.org>
Wed, 5 Nov 2025 11:12:35 +0000 (11:12 +0000)
From the Wireshark development branch:

    commit 4f55543f6b6e5c5d15572889a2cac2b0ec28200e
    Author: John Thacker <johnthacker@gmail.com>
    Date:   Fri Oct 10 11:10:13 2025 -0400

        pidl: Check if a hf is used in a CODE block

        If a field declared in a conformance file appears within a custom
        CODE block in the conformance file, don't warn about the hf being
        unused. This theoretically could have false negatives if a field
        is mentioned only in a comment in the CODE block; we'd have to
        remove the comments with something like Regexp::Common before
        searching to avoid that.

        The current conformance files in the Wireshark distribution don't
        have any such false negative cases, but there are dozens of false
        positives prevented by this change.

Signed-off-by: John Thacker <johnthacker@gmail.com>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
Autobuild-User(master): Andreas Schneider <asn@cryptomilk.org>
Autobuild-Date(master): Wed Nov  5 11:12:35 UTC 2025 on atb-devel-224

pidl/lib/Parse/Pidl/Wireshark/NDR.pm

index b7785d389eebdb6659e383f3e4c94069a012340a..b8833def613b3dc6c0b6a3bf8bb8ef6f00f4f419 100644 (file)
@@ -1371,9 +1371,20 @@ sub DumpFunctionTable($)
 sub CheckUsed($$)
 {
        my ($self, $conformance) = @_;
+
+       # Check if some word appears inside a CODE block
+       # This has false positives if a word appears within a comment.
+       # We could use Regexp::Common to remove comments before searching.
+       local *CheckCode = sub {
+               my $name = shift;
+               return (exists ($conformance->{override}) and ($conformance->{override} =~ /\b$name\b/));
+       };
+
        foreach (values %{$conformance->{header_fields}}) {
                if (not defined($self->{hf_used}->{$_->{INDEX}})) {
-                       warning($_->{POS}, "hf field `$_->{INDEX}' not used");
+                       if (not CheckCode($_->{INDEX})) {
+                               warning($_->{POS}, "hf field `$_->{INDEX}' not used");
+                       }
                }
        }