aboutsummaryrefslogtreecommitdiffstats
path: root/tools/checkAPIs.pl
diff options
context:
space:
mode:
authorAhmad Fatoum <ahmad@a3f.at>2017-08-06 19:00:54 +0200
committerMichael Mann <mmann78@netscape.net>2017-08-07 23:07:24 +0000
commit1089bdb7d4911a5508f86a0eea59418b424b265c (patch)
treeae2045fcde923a772f8bfeccf8403038bd626b32 /tools/checkAPIs.pl
parente63db3ce0ec2e92d69b5e452f71f5c44cd205272 (diff)
checkAPIs.pl: Detect multiple preferences with same variable
Catches mistakes where the same variable is populated by multiple preferences: prefs_register_bool_preference(epl_module, "show_soc_flags", "text1", "desc1", &show_soc_flags); prefs_register_bool_preference(epl_module, "show_soa_flags", "text2", "desc2", &show_soc_flags); Change-Id: I77a9432d9b518e951166c93a890a948d3f228162 Reviewed-on: https://code.wireshark.org/review/22974 Reviewed-by: Michael Mann <mmann78@netscape.net>
Diffstat (limited to 'tools/checkAPIs.pl')
-rwxr-xr-xtools/checkAPIs.pl40
1 files changed, 40 insertions, 0 deletions
diff --git a/tools/checkAPIs.pl b/tools/checkAPIs.pl
index 52ab32abbe..6a9ce159a3 100755
--- a/tools/checkAPIs.pl
+++ b/tools/checkAPIs.pl
@@ -33,6 +33,7 @@
use strict;
use Getopt::Long;
+use Text::Balanced qw(extract_bracketed);
my %APIs = (
# API groups.
@@ -1876,6 +1877,44 @@ sub check_hf_entries($$)
return $errorCount;
}
+sub check_pref_var_dupes($$)
+{
+ my ($filecontentsref, $filename) = @_;
+ my $errorcount = 0;
+
+ # remove macro lines
+ my $filecontents = ${$filecontentsref};
+ $filecontents =~ s { ^\s*\#.*$} []xogm;
+
+ # At what position is the variable in the prefs_register_*_preference() call?
+ my %prefs_register_var_pos = (
+ static_text => undef, obsolete => undef, # ignore
+ decode_as_range => -2, range => -2, filename => -2, # second to last
+ enum => -3, # third to last
+ # everything else is the last argument
+ );
+
+ my @dupes;
+ my %count;
+ while ($filecontents =~ /prefs_register_(\w+?)_preference/gs) {
+ my ($args) = extract_bracketed(substr($filecontents, $+[0]), '()');
+ $args = substr($args, 1, -1); # strip parens
+
+ my $pos = $prefs_register_var_pos{$1};
+ next if exists $prefs_register_var_pos{$1} and not defined $pos;
+ $pos //= -1;
+ my $var = (split /\s*,\s*(?![^(]*\))/, $args)[$pos]; # only commas outside parens
+ push @dupes, $var if $count{$var}++ == 1;
+ }
+
+ if (@dupes) {
+ print STDERR "$filename: error: found these preference variables used in more than one prefs_register_*_preference:\n\t".join(', ', @dupes)."\n";
+ $errorcount++;
+ }
+
+ return $errorcount;
+}
+
sub print_usage
{
print "Usage: checkAPIs.pl [-M] [-h] [-g group1] [-g group2] ... \n";
@@ -2182,6 +2221,7 @@ while ($_ = pop @filelist)
$fileContents =~ s{ $DoubleQuotedStr | $SingleQuotedStr } []xog;
#$errorCount += check_ett_registration(\$fileContents, $filename);
+ $errorCount += check_pref_var_dupes(\$fileContents, $filename);
# Remove all blank lines
$fileContents =~ s{ ^ \s* $ } []xog;