From Sylvain Munaut:

Add support for signed types in _proto_tree_add_bits_ret_val

https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=6363

svn path=/trunk/; revision=39060
This commit is contained in:
Anders Broman 2011-09-20 11:29:53 +00:00
parent 0554530407
commit ec41ae8a1b
1 changed files with 28 additions and 0 deletions

View File

@ -7277,6 +7277,21 @@ _proto_tree_add_bits_ret_val(proto_tree *tree, const int hf_index, tvbuff_t *tvb
return NULL;
}
/* Sign extend for signed types */
switch(hf_field->type){
case FT_INT8:
case FT_INT16:
case FT_INT24:
case FT_INT32:
case FT_INT64:
if (value & (G_GINT64_CONSTANT(1) << (no_of_bits-1)))
value |= (G_GINT64_CONSTANT(-1) << no_of_bits);
break;
default:
break;
}
if(return_value){
*return_value=value;
}
@ -7306,11 +7321,24 @@ _proto_tree_add_bits_ret_val(proto_tree *tree, const int hf_index, tvbuff_t *tvb
fill_label_uint(PITEM_FINFO(pi), lbl_str);
break;
case FT_INT8:
case FT_INT16:
case FT_INT24:
case FT_INT32:
pi = proto_tree_add_int(tree, hf_index, tvb, offset, length, (gint32)value);
fill_label_int(PITEM_FINFO(pi), lbl_str);
break;
case FT_UINT64:
pi = proto_tree_add_uint64(tree, hf_index, tvb, offset, length, value);
fill_label_uint64(PITEM_FINFO(pi), lbl_str);
break;
case FT_INT64:
pi = proto_tree_add_int64(tree, hf_index, tvb, offset, length, (gint64)value);
fill_label_int64(PITEM_FINFO(pi), lbl_str);
break;
default:
DISSECTOR_ASSERT_NOT_REACHED();
return NULL;