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/proto.c | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) (limited to 'epan/proto.c') diff --git a/epan/proto.c b/epan/proto.c index 6252fd5608..ebfa903b81 100644 --- a/epan/proto.c +++ b/epan/proto.c @@ -1493,26 +1493,22 @@ get_int_value(proto_tree *tree, tvbuff_t *tvb, gint offset, gint length, const g switch (length) { case 1: - value = (gint8)tvb_get_guint8(tvb, offset); + value = tvb_get_gint8(tvb, offset); break; case 2: - value = (gint16) (encoding ? tvb_get_letohs(tvb, offset) - : tvb_get_ntohs(tvb, offset)); + value = encoding ? tvb_get_letohis(tvb, offset) + : tvb_get_ntohis(tvb, offset); break; case 3: - value = encoding ? tvb_get_letoh24(tvb, offset) - : tvb_get_ntoh24(tvb, offset); - if (value & 0x00800000) { - /* Sign bit is set; sign-extend it. */ - value |= 0xFF000000; - } + value = encoding ? tvb_get_letohi24(tvb, offset) + : tvb_get_ntohi24(tvb, offset); break; case 4: - value = encoding ? tvb_get_letohl(tvb, offset) - : tvb_get_ntohl(tvb, offset); + value = encoding ? tvb_get_letohil(tvb, offset) + : tvb_get_ntohil(tvb, offset); break; default: @@ -1521,8 +1517,8 @@ get_int_value(proto_tree *tree, tvbuff_t *tvb, gint offset, gint length, const g value = 0; } else { length_error = FALSE; - value = encoding ? tvb_get_letohl(tvb, offset) - : tvb_get_ntohl(tvb, offset); + value = encoding ? tvb_get_letohil(tvb, offset) + : tvb_get_ntohil(tvb, offset); } report_type_length_mismatch(tree, "a signed integer", length, length_error); break; -- cgit v1.2.3