summaryrefslogtreecommitdiff
path: root/tools/checkhf.pl
diff options
context:
space:
mode:
authorBill Meier <wmeier@newsguy.com>2013-02-07 22:16:39 +0000
committerBill Meier <wmeier@newsguy.com>2013-02-07 22:16:39 +0000
commit1e64a82f023614facb189451a7837ca709914a7f (patch)
tree25523e9e01fe03e78a3e68384805e6c3b9218ba9 /tools/checkhf.pl
parent900d29a95eae9a08aa7aec08f6a319ba5265dc80 (diff)
downloadwireshark-1e64a82f023614facb189451a7837ca709914a7f.tar.gz
Add addition test to reduce false positives for 'ERROR: NO ARRAY: '
Essentially: Detect when an hf_... var is effictively initialized via the use of proto_registrar_get_id_byname() or proto_get_id_by_filter_name() (instead of proto_register_field_array()). svn path=/trunk/; revision=47542
Diffstat (limited to 'tools/checkhf.pl')
-rwxr-xr-xtools/checkhf.pl50
1 files changed, 46 insertions, 4 deletions
diff --git a/tools/checkhf.pl b/tools/checkhf.pl
index 8618f51597..5edaabdd3f 100755
--- a/tools/checkhf.pl
+++ b/tools/checkhf.pl
@@ -112,9 +112,10 @@ while (my $fileName = $ARGV[0]) {
remove_quoted_strings(\$fileContents, $fileName);
remove_if0_code (\$fileContents, $fileName);
- find_remove_hf_defs (\$fileContents, $fileName, \%hfDefs);
- find_remove_hf_array_entries(\$fileContents, $fileName, \%hfArrayEntries);
- find_hf_usage (\$fileContents, $fileName, \%hfUsage);
+ find_remove_hf_defs (\$fileContents, $fileName, \%hfDefs);
+ find_remove_hf_array_entries (\$fileContents, $fileName, \%hfArrayEntries);
+ find_remove_proto_get_id_hf_assignments(\$fileContents, $fileName, \%hfArrayEntries);
+ find_hf_usage (\$fileContents, $fileName, \%hfUsage);
# Tests (See above)
# 1. Are all the static hfDefs entries in hfUsage ?
@@ -438,7 +439,7 @@ sub find_remove_hf_array_entries {
# find all the hf[] entries (searching $$codeRef).
while ($$codeRef =~ m{ $hfArrayEntryRegEx }xosg) {
($debug == 98) && print "+++ $1 $2\n";
- $hfArrayEntriesHRef->{$1} = 1;
+ $hfArrayEntriesHRef->{$1} = undef;
}
($debug == 4) && debug_print_hash("AE: $fileName", $hfArrayEntriesHRef); # ArrayEntry
@@ -451,6 +452,47 @@ sub find_remove_hf_array_entries {
}
# ---------------------------------------------------------------------
+# action: Add to hash an entry (hf_...) for each hf_... var
+# found in statements of the form:
+# 'hf_... = proto_registrar_get_id_byname ...'
+# 'hf_... = proto_get_id_by_filtername ...'
+# Remove each such statement found from the input string.
+# args: codeRef, fileName, hfArrayEntriesHRef
+
+sub find_remove_proto_get_id_hf_assignments {
+ my ($codeRef, $fileName, $hfArrayEntriesHRef) = @_;
+
+ my $RegEx = qr / ( hf_ [a-zA-Z0-9_]+ )
+ \s* = \s*
+ (?: proto_registrar_get_id_byname | proto_get_id_by_filter_name )
+ /xo;
+
+ my @hfvars = $$codeRef =~ / $RegEx /xog;
+
+ if (@hfvars == 0) {
+ return;
+ }
+
+ # found:
+ # Sanity check: hf_vars shouldn't already be in hfArrayEntries
+ if (defined @$hfArrayEntriesHRef{@hfvars}) {
+ printf "? one or more of [@hfvars] initialized via proto_registrar_get_by_name() also in hf[] ??\n";
+ }
+
+ # Now: add to hfArrayEntries
+ @$hfArrayEntriesHRef{@hfvars} = ();
+
+ ($debug == 4) && debug_print_hash("PR: $fileName", $hfArrayEntriesHRef);
+
+ # remove from input (so not considered as 'usage')
+ $$codeRef =~ s/ $RegEx //xog;
+
+ ($debug == 4) && print "==> After remove proto_registrar_by_name: code: [$fileName]\n$$codeRef\n===<\n";
+
+ return;
+}
+
+# ---------------------------------------------------------------------
# action: Add to hash all hf_... strings remaining in input string.
# arga: codeRef, fileName, hfUsageHRef
# return: ref to hfUsage hash