aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormorriss <morriss@f5534014-38df-0310-8fa8-9805f1628bb7>2012-02-08 14:15:01 +0000
committermorriss <morriss@f5534014-38df-0310-8fa8-9805f1628bb7>2012-02-08 14:15:01 +0000
commit58731ab376ad0eba0d14440837b4ecc9c1f71576 (patch)
tree6a871f98d8da386bfeecde6771e67539852a05cb
parent2349c3abe4a1de11bce2226c9b7e315ecfb177fe (diff)
As suggested by Joerg on the -dev list yesterday: count up the number of
proto_tree_add_text() calls and compare that to the number of proto_tree_add_<something else>() calls and complain if more than 50% of the calls are add_text()'s. proto_tree_add_text() calls whose returned proto_item is used are not counted as hanging a subtree off a text item is an appropriate use for text items. I chose 50% because even at that level there are many dissectors with "too many" proto_tree_add_text()'s. The function to do all of this is commented out for now for the same reason plus the fact that it's pretty slow. git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@40930 f5534014-38df-0310-8fa8-9805f1628bb7
-rwxr-xr-xtools/checkAPIs.pl40
1 files changed, 39 insertions, 1 deletions
diff --git a/tools/checkAPIs.pl b/tools/checkAPIs.pl
index 6ba8736805..fd469eb5cb 100755
--- a/tools/checkAPIs.pl
+++ b/tools/checkAPIs.pl
@@ -1303,6 +1303,43 @@ sub findAPIinFile($$$)
}
}
+sub checkAddTextCalls($$)
+{
+ my ($fileContentsRef, $filename) = @_;
+ my $add_text_count = 0;
+ my $okay_add_text_count = 0;
+ my $add_xxx_count = 0;
+
+ # First count how many proto_tree_add_text() calls there are in total
+ while (${$fileContentsRef} =~ m/ \W* proto_tree_add_text \W* \( /gox) {
+ $add_text_count++;
+ }
+ # Then count how many of them are "okay" by virtue of their generate proto_item
+ # being used (e.g., to hang a subtree off of)
+ while (${$fileContentsRef} =~ m/ \W* [a-zA-Z0-9]+ \W* = \W* proto_tree_add_text \W* \( /gox) {
+ $okay_add_text_count++;
+ }
+ # Then count how many proto_tree_add_*() calls there are
+ while (${$fileContentsRef} =~ m/ \W proto_tree_add_[a-z]+ \W* \( /gox) {
+ $add_xxx_count++;
+ }
+
+ #printf "add_text_count %d, okay_add_text_count %d\n", $add_text_count, $okay_add_text_count;
+ $add_xxx_count -= $add_text_count;
+ $add_text_count -= $okay_add_text_count;
+
+ # Don't bother with files with small counts
+ if ($add_xxx_count < 10 || $add_text_count < 10) {
+ return;
+ }
+
+ my $percentage = 100*$add_text_count/$add_xxx_count;
+ if ($percentage > 50) {
+ printf "%s: found %d useless add_text() vs. %d add_<something else>() calls (%.2f%%)\n",
+ $filename, $add_text_count, $add_xxx_count, $percentage;
+ }
+}
+
# APIs which (generally) should not be called with an argument of tvb_get_ptr()
my @TvbPtrAPIs = (
# Use NULL for the value_ptr instead of tvb_get_ptr() (only if the
@@ -1668,11 +1705,12 @@ while ($_ = $ARGV[0])
}
#checkAPIsCalledWithTvbGetPtr(\@TvbPtrAPIs, \$fileContents, \@foundAPIs);
-
#if (@foundAPIs) {
# print STDERR "Found APIs with embedded tvb_get_ptr() calls in ".$filename.": ".join(',', @foundAPIs)."\n"
#}
+ #checkAddTextCalls(\$fileContents, $filename);
+
# Brute force check for value_string arrays which are missing {0, NULL} as the final (terminating) array entry
if ($check_value_string_array_null_termination) {
# Assumption: definition is of form (pseudo-Regex):