From 76a69be324fd109bec2c4693e4ab57b9bc140c58 Mon Sep 17 00:00:00 2001 From: Guy Harris Date: Tue, 28 Apr 2020 10:27:28 -0700 Subject: [PATCH] If possible use proto_tree_add_item(), not proto_tree_add_bytes_item(). Only use proto_tree_add_bytes_item() if you 1) are processing a hex string rather than binary byte array; 2) need the raw byte data. While we're at it, fix the encoding argument in some calls adding FT_BYTES fields to be ENC_NA, and, for some cases that could use FT_UINT_BYTES, use proto_tree_add_item_ret_uint() to handle the length and add a comment about that. Change-Id: I6a1baca5c7da3001c0a6669f9c251e9773346c8c Reviewed-on: https://code.wireshark.org/review/36967 Petri-Dish: Guy Harris Tested-by: Petri Dish Buildbot Reviewed-by: Guy Harris --- epan/dissectors/packet-ieee802154.c | 2 +- epan/dissectors/packet-netlink-net_dm.c | 2 +- epan/dissectors/packet-optommp.c | 9 ++------- epan/dissectors/packet-wifi-nan.c | 20 +++++++++++--------- 4 files changed, 15 insertions(+), 18 deletions(-) diff --git a/epan/dissectors/packet-ieee802154.c b/epan/dissectors/packet-ieee802154.c index 56d5b7bb30..b483697c15 100644 --- a/epan/dissectors/packet-ieee802154.c +++ b/epan/dissectors/packet-ieee802154.c @@ -3297,7 +3297,7 @@ dissect_ieee802154_tap_tlvs(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) break; } default: - proto_tree_add_bytes_item(tlvtree, hf_ieee802154_tap_tlv_unknown, tvb, offset, length, ENC_NA, NULL, NULL, NULL); + proto_tree_add_item(tlvtree, hf_ieee802154_tap_tlv_unknown, tvb, offset, length, ENC_NA); proto_item_append_text(proto_tree_get_parent(tlvtree), "Unknown TLV"); break; } /* switch (tlv_type) */ diff --git a/epan/dissectors/packet-netlink-net_dm.c b/epan/dissectors/packet-netlink-net_dm.c index 6ccaa61c07..d69d68bd01 100644 --- a/epan/dissectors/packet-netlink-net_dm.c +++ b/epan/dissectors/packet-netlink-net_dm.c @@ -394,7 +394,7 @@ dissect_net_dm_attrs(tvbuff_t *tvb, void *data, struct packet_netlink_data *nl_d proto_tree_add_item(tree, &hfi_net_dm_hw, tvb, offset, len, nl_data->encoding); return 1; case WS_NET_DM_ATTR_FLOW_ACTION_COOKIE: - proto_tree_add_bytes_item(tree, &hfi_net_dm_flow_action_cookie, tvb, offset, len, ENC_NA, NULL, NULL, NULL); + proto_tree_add_item(tree, &hfi_net_dm_flow_action_cookie, tvb, offset, len, ENC_NA); return 1; default: return 0; diff --git a/epan/dissectors/packet-optommp.c b/epan/dissectors/packet-optommp.c index 6d41ce65c8..2e2eb74f11 100644 --- a/epan/dissectors/packet-optommp.c +++ b/epan/dissectors/packet-optommp.c @@ -736,13 +736,8 @@ static void dissect_optommp_data_block_byte(proto_item **ti, proto_tree *tree, { if( tvb_reported_length(tvb) >= *poffset + 1 ) { - GByteArray *unused_ret_val = NULL; - unused_ret_val = g_byte_array_new(); - /* CheckAPI.pl complained when using ENC_BIG_ENDIAN as the sixth - * parameter, so set it to 0x0 */ - *ti = proto_tree_add_bytes_item(tree, hf_optommp_data_block_byte, tvb, - *poffset, 1, 0x0, unused_ret_val, NULL, NULL); - g_byte_array_free(unused_ret_val, TRUE); + *ti = proto_tree_add_item(tree, hf_optommp_data_block_byte, tvb, + *poffset, 1, ENC_NA); } ++(*poffset); diff --git a/epan/dissectors/packet-wifi-nan.c b/epan/dissectors/packet-wifi-nan.c index 33af154553..2b4d2b5241 100644 --- a/epan/dissectors/packet-wifi-nan.c +++ b/epan/dissectors/packet-wifi-nan.c @@ -973,11 +973,13 @@ dissect_attr_sda(proto_tree* attr_tree, tvbuff_t* tvb, gint offset, guint16 attr if (service_ctr_byte & BITMASK_SERVICE_INFO_PRESENT) { - proto_tree_add_item(attr_tree, hf_nan_attr_sda_service_info_len, tvb, - offset, 1, ENC_BIG_ENDIAN); - gint service_info_len = tvb_get_guint8(tvb, offset); - proto_tree_add_bytes_item(attr_tree, hf_nan_attr_sda_service_info, tvb, - offset + 1, service_info_len, ENC_BIG_ENDIAN, NULL, NULL, NULL); + guint32 service_info_len; + + /* XXX - use FT_UINT_BYTES? */ + proto_tree_add_item_ret_uint(attr_tree, hf_nan_attr_sda_service_info_len, tvb, + offset, 1, ENC_BIG_ENDIAN, &service_info_len); + proto_tree_add_item(attr_tree, hf_nan_attr_sda_service_info, tvb, + offset + 1, service_info_len, ENC_NA); // offset += service_info_len + 1; } } @@ -1540,8 +1542,8 @@ dissect_attr_availability(proto_tree* attr_tree, tvbuff_t* tvb, gint offset, gui time_bitmap_ctr_fields, ENC_LITTLE_ENDIAN); proto_tree_add_item_ret_uint(entry_tree, hf_nan_time_bitmap_len, tvb, offset + 2, 1, ENC_LITTLE_ENDIAN, &time_bitmap_len); - proto_tree_add_bytes_item(entry_tree, hf_nan_time_bitmap, tvb, - offset + 3, time_bitmap_len, ENC_BIG_ENDIAN, NULL, NULL, NULL); + proto_tree_add_item(entry_tree, hf_nan_time_bitmap, tvb, + offset + 3, time_bitmap_len, ENC_NA); hdr_len = 5; offset += 3 + time_bitmap_len; } @@ -1669,8 +1671,8 @@ dissect_attr_ndc(proto_tree* attr_tree, tvbuff_t* tvb, gint offset, guint16 attr time_bitmap_ctr_fields, ENC_LITTLE_ENDIAN); proto_tree_add_item(entry_tree, hf_nan_time_bitmap_len, tvb, offset + 3, 1, ENC_BIG_ENDIAN); - proto_tree_add_bytes_item(entry_tree, hf_nan_time_bitmap, tvb, - offset + 4, time_bitmap_len, ENC_BIG_ENDIAN, NULL, NULL, NULL); + proto_tree_add_item(entry_tree, hf_nan_time_bitmap, tvb, + offset + 4, time_bitmap_len, ENC_NA); offset += time_bitmap_len + 4; dissected_len += time_bitmap_len + 4;