From c7970d9356a494d847101c2bd92e4ca97a7d3d58 Mon Sep 17 00:00:00 2001 From: Guy Harris Date: Mon, 9 Apr 2018 23:06:47 -0700 Subject: Add, and use, "fetch signed value" for lengths < 40 bits. Add 8-bit, 16-bit, 24-bit, and 32-bit "fetch signed value" routines, and use them rather than casting the result of the 8/16/24/32-bit "fetch unsigned value" routines to a signed type (which, BTW, isn't sufficient for 24-bit values, so this appears to fix a bug in epan/dissectors/packet-zbee-zcl.c). Use numbers rather than sizeof()s in various tvb_get_ routines. Change-Id: I0e48a57fac9f70fe42de815c3fa915f1592548bd Reviewed-on: https://code.wireshark.org/review/26844 Petri-Dish: Guy Harris Tested-by: Petri Dish Buildbot Reviewed-by: Anders Broman --- epan/dissectors/packet-btatt.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'epan/dissectors/packet-btatt.c') diff --git a/epan/dissectors/packet-btatt.c b/epan/dissectors/packet-btatt.c index fc49b5c6fa..3edcb2628c 100644 --- a/epan/dissectors/packet-btatt.c +++ b/epan/dissectors/packet-btatt.c @@ -10512,9 +10512,9 @@ dissect_btgatt_microbit_accelerometer_data(tvbuff_t *tvb, packet_info *pinfo _U_ if (bluetooth_gatt_has_no_parameter(att_data->opcode)) return -1; - x_axis = (gdouble) (gint16) tvb_get_guint16(tvb, offset, ENC_LITTLE_ENDIAN) / 1000.0; - y_axis = (gdouble) (gint16) tvb_get_guint16(tvb, offset+2, ENC_LITTLE_ENDIAN) / 1000.0; - z_axis = (gdouble) (gint16) tvb_get_guint16(tvb, offset+4, ENC_LITTLE_ENDIAN) / 1000.0; + x_axis = (gdouble) tvb_get_gint16(tvb, offset, ENC_LITTLE_ENDIAN) / 1000.0; + y_axis = (gdouble) tvb_get_gint16(tvb, offset+2, ENC_LITTLE_ENDIAN) / 1000.0; + z_axis = (gdouble) tvb_get_gint16(tvb, offset+4, ENC_LITTLE_ENDIAN) / 1000.0; sub_item = proto_tree_add_item(tree, hf_gatt_microbit_accelerometer_data, tvb, 0, tvb_captured_length(tvb), ENC_NA); sub_tree = proto_item_add_subtree(sub_item, ett_btgatt_microbit_accelerometer); @@ -10557,9 +10557,9 @@ dissect_btgatt_microbit_magnetometer_data(tvbuff_t *tvb, packet_info *pinfo _U_, if (bluetooth_gatt_has_no_parameter(att_data->opcode)) return -1; - x_axis = (gdouble) (gint16) tvb_get_guint16(tvb, offset, ENC_LITTLE_ENDIAN) / 1000.0; - y_axis = (gdouble) (gint16) tvb_get_guint16(tvb, offset+2, ENC_LITTLE_ENDIAN) / 1000.0; - z_axis = (gdouble) (gint16) tvb_get_guint16(tvb, offset+4, ENC_LITTLE_ENDIAN) / 1000.0; + x_axis = (gdouble) tvb_get_gint16(tvb, offset, ENC_LITTLE_ENDIAN) / 1000.0; + y_axis = (gdouble) tvb_get_gint16(tvb, offset+2, ENC_LITTLE_ENDIAN) / 1000.0; + z_axis = (gdouble) tvb_get_gint16(tvb, offset+4, ENC_LITTLE_ENDIAN) / 1000.0; sub_item = proto_tree_add_item(tree, hf_gatt_microbit_magnetometer_data, tvb, 0, tvb_captured_length(tvb), ENC_NA); sub_tree = proto_item_add_subtree(sub_item, ett_btgatt_microbit_magnetometer); -- cgit v1.2.3