forked from osmocom/wireshark
CBOR: get rid of INFINITY and NAN defines
This triggers an "overflow in constant arithmetic" warning with MSVC2013 Change-Id: Ie3b076019c4722857c8e57f8568a0cb124fd13ad Reviewed-on: https://code.wireshark.org/review/10217 Petri-Dish: Pascal Quantin <pascal.quantin@gmail.com> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Pascal Quantin <pascal.quantin@gmail.com>
This commit is contained in:
parent
4f68c52eda
commit
ce38df527f
|
@ -562,29 +562,35 @@ dissect_cbor_tag(tvbuff_t *tvb, packet_info *pinfo, proto_tree *cbor_tree, gint
|
||||||
}
|
}
|
||||||
|
|
||||||
/* based on code from rfc7049 appendix-D */
|
/* based on code from rfc7049 appendix-D */
|
||||||
static float decode_half(const int half) {
|
static proto_item *decode_half(tvbuff_t *tvb, proto_tree *tree, gint *offset, int hfindex) {
|
||||||
int exponent = (half >> 10) & 0x1f;
|
int half, exponent, mantissa;
|
||||||
int mantissa = half & 0x3ff;
|
|
||||||
float val;
|
float val;
|
||||||
|
proto_item *item;
|
||||||
|
|
||||||
if (exponent == 0)
|
half = tvb_get_ntohs(tvb, *offset);
|
||||||
|
exponent = (half >> 10) & 0x1f;
|
||||||
|
mantissa = half & 0x3ff;
|
||||||
|
|
||||||
|
if (exponent == 0) {
|
||||||
val = ldexpf((float)mantissa, -24);
|
val = ldexpf((float)mantissa, -24);
|
||||||
else if (exponent != 31)
|
item = proto_tree_add_float(tree, hfindex, tvb, *offset, 2,
|
||||||
|
half & 0x8000 ? -val : val);
|
||||||
|
} else if (exponent != 31) {
|
||||||
val = ldexpf((float)(mantissa + 1024), exponent - 25);
|
val = ldexpf((float)(mantissa + 1024), exponent - 25);
|
||||||
else {
|
item = proto_tree_add_float(tree, hfindex, tvb, *offset, 2,
|
||||||
if (mantissa == 0)
|
half & 0x8000 ? -val : val);
|
||||||
val = INFINITY;
|
} else {
|
||||||
else
|
item = proto_tree_add_float_format_value(tree, hfindex, tvb, *offset, 2,
|
||||||
val = NAN;
|
0, "%s", mantissa == 0 ? "INFINITY" : "NAN");
|
||||||
}
|
}
|
||||||
return half & 0x8000 ? -val : val;
|
*offset += 2;
|
||||||
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
static proto_item *
|
static proto_item *
|
||||||
dissect_cbor_float_simple_data(tvbuff_t *tvb, packet_info *pinfo, proto_tree *cbor_tree, gint *offset, guint8 type_minor)
|
dissect_cbor_float_simple_data(tvbuff_t *tvb, packet_info *pinfo, proto_tree *cbor_tree, gint *offset, guint8 type_minor)
|
||||||
{
|
{
|
||||||
proto_item *item;
|
proto_item *item;
|
||||||
int half;
|
|
||||||
|
|
||||||
switch (type_minor) {
|
switch (type_minor) {
|
||||||
case 0x18:
|
case 0x18:
|
||||||
|
@ -594,9 +600,7 @@ dissect_cbor_float_simple_data(tvbuff_t *tvb, packet_info *pinfo, proto_tree *cb
|
||||||
return item;
|
return item;
|
||||||
case 0x19:
|
case 0x19:
|
||||||
*offset += 1;
|
*offset += 1;
|
||||||
half = tvb_get_ntohs(tvb, *offset);
|
item = decode_half(tvb, cbor_tree, offset, hf_cbor_type_float16);
|
||||||
item = proto_tree_add_float(cbor_tree, hf_cbor_type_float16, tvb, *offset, 2, decode_half(half));
|
|
||||||
*offset += 2;
|
|
||||||
return item;
|
return item;
|
||||||
case 0x1a:
|
case 0x1a:
|
||||||
*offset += 1;
|
*offset += 1;
|
||||||
|
|
Loading…
Reference in New Issue