diff options
author | Michael Mann <mmann78@netscape.net> | 2017-05-13 20:05:52 -0400 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2017-05-14 01:57:37 +0000 |
commit | 21735ead4f907b1323b5fd72ea698372774e0ee5 (patch) | |
tree | 9caa650b7aabb235525f75eead8548afe9da0dcb | |
parent | bd3e24f0dab1fb3d4846d54e32f837f56674a9c1 (diff) | |
download | wireshark-21735ead4f907b1323b5fd72ea698372774e0ee5.tar.gz |
Add unit_name_string_get_double to handle float/double fields
Bug: 13705
Change-Id: I6bd006f216440d071e5c1eeb6b1f996b4a364c62
Reviewed-on: https://code.wireshark.org/review/21629
Reviewed-by: Michael Mann <mmann78@netscape.net>
Petri-Dish: Michael Mann <mmann78@netscape.net>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Guy Harris <guy@alum.mit.edu>
-rw-r--r-- | debian/libwireshark0.symbols | 1 | ||||
-rw-r--r-- | epan/proto.c | 8 | ||||
-rw-r--r-- | epan/unit_strings.c | 8 | ||||
-rw-r--r-- | epan/unit_strings.h | 1 |
4 files changed, 14 insertions, 4 deletions
diff --git a/debian/libwireshark0.symbols b/debian/libwireshark0.symbols index f56dbc05bc..daa1339cc5 100644 --- a/debian/libwireshark0.symbols +++ b/debian/libwireshark0.symbols @@ -1698,6 +1698,7 @@ libwireshark.so.0 libwireshark0 #MINVER# union_of_tap_listener_flags@Base 1.9.1 unit_name_string_get_value@Base 2.3.0 unit_name_string_get_value64@Base 2.3.0 + unit_name_string_get_double@Base 2.3.0 units_bit_bits@Base 2.3.0 units_bit_sec@Base 2.3.0 units_byte_bytes@Base 2.3.0 diff --git a/epan/proto.c b/epan/proto.c index 00318d6585..c9309fce59 100644 --- a/epan/proto.c +++ b/epan/proto.c @@ -5626,7 +5626,7 @@ proto_custom_set(proto_tree* tree, GSList *field_ids, gint occurrence, double d_value = fvalue_get_floating(&finfo->value); g_snprintf(result+offset_r, size-offset_r, "%." G_STRINGIFY(FLT_DIG) "g%s", d_value, - unit_name_string_get_value64((guint64)d_value, (unit_name_string*)hfinfo->strings)); + unit_name_string_get_double(d_value, (unit_name_string*)hfinfo->strings)); } else { g_snprintf(result+offset_r, size-offset_r, "%." G_STRINGIFY(FLT_DIG) "g", fvalue_get_floating(&finfo->value)); @@ -5639,7 +5639,7 @@ proto_custom_set(proto_tree* tree, GSList *field_ids, gint occurrence, double d_value = fvalue_get_floating(&finfo->value); g_snprintf(result+offset_r, size-offset_r, "%." G_STRINGIFY(DBL_DIG) "g%s", d_value, - unit_name_string_get_value64((guint64)d_value, (unit_name_string*)hfinfo->strings)); + unit_name_string_get_double(d_value, (unit_name_string*)hfinfo->strings)); } else { g_snprintf(result+offset_r, size-offset_r, "%." G_STRINGIFY(DBL_DIG) "g", fvalue_get_floating(&finfo->value)); @@ -7854,7 +7854,7 @@ proto_item_fill_label(field_info *fi, gchar *label_str) g_snprintf(label_str, ITEM_LABEL_LENGTH, "%s: %." G_STRINGIFY(FLT_DIG) "g%s", hfinfo->name, d_value, - unit_name_string_get_value64((guint64)d_value, (unit_name_string*)hfinfo->strings)); + unit_name_string_get_double(d_value, (unit_name_string*)hfinfo->strings)); } else { g_snprintf(label_str, ITEM_LABEL_LENGTH, "%s: %." G_STRINGIFY(FLT_DIG) "g", @@ -7869,7 +7869,7 @@ proto_item_fill_label(field_info *fi, gchar *label_str) g_snprintf(label_str, ITEM_LABEL_LENGTH, "%s: %." G_STRINGIFY(DBL_DIG) "g%s", hfinfo->name, d_value, - unit_name_string_get_value64((guint64)d_value, (unit_name_string*)hfinfo->strings)); + unit_name_string_get_double(d_value, (unit_name_string*)hfinfo->strings)); } else { g_snprintf(label_str, ITEM_LABEL_LENGTH, "%s: %." G_STRINGIFY(DBL_DIG) "g", diff --git a/epan/unit_strings.c b/epan/unit_strings.c index abefaa51bc..584681f28b 100644 --- a/epan/unit_strings.c +++ b/epan/unit_strings.c @@ -42,6 +42,14 @@ char* unit_name_string_get_value64(guint64 value, unit_name_string* units) return plurality(value, units->singular, units->plural); } +char* unit_name_string_get_double(double value, unit_name_string* units) +{ + if (units->plural == NULL) + return units->singular; + + return plurality(value, units->singular, units->plural); +} + /* * A default set of unit strings that dissectors can use for * header fields. Some units intentionally have a space diff --git a/epan/unit_strings.h b/epan/unit_strings.h index e31f61e95b..45e58c3bb6 100644 --- a/epan/unit_strings.h +++ b/epan/unit_strings.h @@ -41,6 +41,7 @@ typedef struct unit_name_string { WS_DLL_PUBLIC char* unit_name_string_get_value(guint32 value, unit_name_string* units); WS_DLL_PUBLIC char* unit_name_string_get_value64(guint64 value, unit_name_string* units); +WS_DLL_PUBLIC char* unit_name_string_get_double(double value, unit_name_string* units); /* * A default set of unit strings that dissectors can use for |