aboutsummaryrefslogtreecommitdiffstats
path: root/epan/proto.c
diff options
context:
space:
mode:
authorPascal Quantin <pascal.quantin@gmail.com>2016-09-27 23:57:29 +0200
committerAnders Broman <a.broman58@gmail.com>2016-09-28 06:07:01 +0000
commit152e245804397bfcd0fc3e4cfac22e1d49b0b169 (patch)
tree3ed21c5c6178a39c59409ddaa7859c2d59de5163 /epan/proto.c
parentf8b32e5b4edac7c4ca9932aacef64b48e514b577 (diff)
proto_tree_add_item_ret_(u)int/proto_tree_add_bitmask_with_flags_ret_uint64: return real value
Apply mask and bit shift on the returned value. Change-Id: I00aebc854756f01a25199a259d6d5252abea4349 Reviewed-on: https://code.wireshark.org/review/17958 Reviewed-by: Anders Broman <a.broman58@gmail.com>
Diffstat (limited to 'epan/proto.c')
-rw-r--r--epan/proto.c28
1 files changed, 26 insertions, 2 deletions
diff --git a/epan/proto.c b/epan/proto.c
index d610e08a5f..dfbff4bc34 100644
--- a/epan/proto.c
+++ b/epan/proto.c
@@ -2324,8 +2324,18 @@ proto_tree_add_item_ret_int(proto_tree *tree, int hfindex, tvbuff_t *tvb,
/* I believe it's ok if this is called with a NULL tree */
value = get_int_value(tree, tvb, start, length, encoding);
- if (retval)
+ if (retval) {
+ gint no_of_bits;
*retval = value;
+ if (hfinfo->bitmask) {
+ /* Mask out irrelevant portions */
+ *retval &= (guint32)(hfinfo->bitmask);
+ /* Shift bits */
+ *retval >>= hfinfo_bitshift(hfinfo);
+ }
+ no_of_bits = ws_count_ones(hfinfo->bitmask);
+ *retval = ws_sign_ext32(*retval, no_of_bits);
+ }
CHECK_FOR_NULL_TREE(tree);
@@ -2376,8 +2386,15 @@ proto_tree_add_item_ret_uint(proto_tree *tree, int hfindex, tvbuff_t *tvb,
/* XXX - modify if we ever support EBCDIC FT_CHAR */
value = get_uint_value(tree, tvb, start, length, encoding);
- if (retval)
+ if (retval) {
*retval = value;
+ if (hfinfo->bitmask) {
+ /* Mask out irrelevant portions */
+ *retval &= (guint32)(hfinfo->bitmask);
+ /* Shift bits */
+ *retval >>= hfinfo_bitshift(hfinfo);
+ }
+ }
CHECK_FOR_NULL_TREE(tree);
@@ -9531,6 +9548,13 @@ proto_tree_add_bitmask_with_flags_ret_uint64(proto_tree *parent_tree, tvbuff_t *
}
*retval = value;
+ if (hf->bitmask) {
+ /* Mask out irrelevant portions */
+ *retval &= hf->bitmask;
+ /* Shift bits */
+ *retval >>= hfinfo_bitshift(hf);
+ }
+
return item;
}