summaryrefslogtreecommitdiff
path: root/epan
diff options
context:
space:
mode:
authorChristian Lamparter <chunkeey@googlemail.com>2016-02-16 20:12:00 +0100
committerPascal Quantin <pascal.quantin@gmail.com>2016-02-17 13:16:42 +0000
commit6671b0dea8a4b724814b698f7418d4c5d07c461a (patch)
tree9379ee759711fef1f0b8590eb8adbbfad880deb6 /epan
parent2d133d62ab7a1cbe141138b90b399dad71113f06 (diff)
downloadwireshark-6671b0dea8a4b724814b698f7418d4c5d07c461a.tar.gz
usb: cleanup idProduct dissection
The current code which dissects the idProduct (and to some extend the idVendor) item for USB devices is overly complicated. A better method to format the product string in the right way is using: proto_tree_add_uint_format_value. This gets rid of the additinal string and item manipulation altogether. Change-Id: Iadd69b7dc284e62039402de53418f41460d88a5d Reviewed-on: https://code.wireshark.org/review/13973 Petri-Dish: Pascal Quantin <pascal.quantin@gmail.com> Petri-Dish: Gerald Combs <gerald@wireshark.org> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Pascal Quantin <pascal.quantin@gmail.com>
Diffstat (limited to 'epan')
-rw-r--r--epan/dissectors/packet-usb.c25
1 files changed, 7 insertions, 18 deletions
diff --git a/epan/dissectors/packet-usb.c b/epan/dissectors/packet-usb.c
index 0ce32a8377..086d68f44d 100644
--- a/epan/dissectors/packet-usb.c
+++ b/epan/dissectors/packet-usb.c
@@ -1444,12 +1444,9 @@ dissect_usb_device_descriptor(packet_info *pinfo, proto_tree *parent_tree,
int old_offset = offset;
guint32 protocol;
const gchar *description;
- guint16 vendor_id;
+ guint32 vendor_id;
guint32 product;
guint16 product_id;
- guint8 *field_description;
- gint field_description_length;
- header_field_info *hfi;
tree = proto_tree_add_subtree(parent_tree, tvb, offset, -1, ett_descriptor_device, &item, "DEVICE DESCRIPTOR");
@@ -1489,26 +1486,18 @@ dissect_usb_device_descriptor(packet_info *pinfo, proto_tree *parent_tree,
}
/* idVendor */
- proto_tree_add_item(tree, hf_usb_idVendor, tvb, offset, 2, ENC_LITTLE_ENDIAN);
- vendor_id = tvb_get_letohs(tvb, offset);
- usb_conv_info->deviceVendor = vendor_id;
+ proto_tree_add_item_ret_uint(tree, hf_usb_idVendor, tvb, offset, 2, ENC_LITTLE_ENDIAN, &vendor_id);
+ usb_conv_info->deviceVendor = (guint16)vendor_id;
offset += 2;
/* idProduct */
- nitem = proto_tree_add_item(tree, hf_usb_idProduct, tvb, offset, 2, ENC_LITTLE_ENDIAN);
product_id = tvb_get_letohs(tvb, offset);
usb_conv_info->deviceProduct = product_id;
- product = vendor_id << 16 | product_id;
+ product = (guint16)vendor_id << 16 | product_id;
- hfi = proto_registrar_get_nth(hf_usb_idProduct);
- field_description_length = (gint)strlen(hfi->name) + 14;
- field_description = (guint8 *)wmem_alloc(wmem_packet_scope(), field_description_length);
- g_strlcpy(field_description, hfi->name, field_description_length);
- g_strlcat(field_description, ": %s (0x%04x)", field_description_length);
-
- proto_item_set_text(nitem, field_description,
- val_to_str_ext_const(product, &ext_usb_products_vals, "Unknown"),
- product_id);
+ proto_tree_add_uint_format_value(tree, hf_usb_idProduct, tvb, offset, 2, product_id, "%s (0x%04x)",
+ val_to_str_ext_const(product, &ext_usb_products_vals, "Unknown"),
+ product_id);
offset += 2;
if (!pinfo->fd->flags.visited) {