This is a static archive of our old Q&A Site. Please post any new questions and answers at ask.wireshark.org.

proto_tree_add_text() flagged by checkAPIs tool as “useless”

0

Trying to submit Control Techniques packet-ecmp.c dissector as a built-in. Wireshark team requested that I run the checkAPIs tool on the source file. It gave this result.

$ checkAPIs.pl packet-ecmp.c packet-ecmp.c: found 324 useless add_text() vs. 119 add_<something else="">() calls (272.27%) $

Checked this with the Visual C++ editor and essentially all the flagged lines are references to proto_tree_add_text(...) source lines. Latest copy of README.dissector shows this proto_tree_add_text() function as legal and acceptable.

There are several functions that the programmer can use to add either protocol or field labels to the proto_tree: proto_item proto_tree_add_item(tree, id, tvb, start, length, encoding); proto_item proto_tree_add_text(tree, tvb, start, length, format, ...);

OK, what gives?

This question is marked "community wiki".

asked 26 Sep '14, 07:41

lynchzilla's gravatar image

lynchzilla
26447
accept rate: 0%

edited 26 Sep '14, 08:47


One Answer:

1

proto_tree_add_text() has long been on the list of APIs to avoid and we've been slowly replacing most calls to it with better APIs (ones which make the field filterable). As README.dissector says (in master-1.12):

This can (and should only) be used for items with subtrees, which may not
have values themselves - the items in the subtree are the ones with values.
In other words, if you're using proto_tree_add_text() and not using the
return value to build a new tree, you probably shouldn't be using this
function: you probably should be using proto_tree_add_item() instead.

The current README.dissector (in master) doesn't even mention proto_tree_add_text() any more. (Keep in mind that new dissectors are submitted against master, not one of the release branches.)

answered 26 Sep '14, 08:48

JeffMorriss's gravatar image

JeffMorriss ♦
6.2k572
accept rate: 27%