From 23a1b085ff3a0145ff6fd49eedfab6999704932a Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Sun, 3 Feb 2019 19:13:26 +0100 Subject: ftypes: make conversion of FT_DOUBLE to string locale-independent Use a locale-independent glib routine to format floating point numbers. This avoids displaying floating point numbers as "86399,9921875" with LC_ALL=nl_NL.UTF-8. This output is consistent with val_from_unparsed which is used for parsing display filter values and is already locale-independent. Note that the displayed node labels in the dissection tree is still locale-dependent (see proto_item_fill_label for FT_DOUBLE). Bug: 15437 Change-Id: I64dd2b7dbb453022edf88b3052e2f67066189427 Reviewed-on: https://code.wireshark.org/review/31869 Petri-Dish: Peter Wu Tested-by: Petri Dish Buildbot Reviewed-by: Peter Wu --- epan/ftypes/ftype-double.c | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/epan/ftypes/ftype-double.c b/epan/ftypes/ftype-double.c index dcceea2c6d..39fcccb28f 100644 --- a/epan/ftypes/ftype-double.c +++ b/epan/ftypes/ftype-double.c @@ -16,8 +16,6 @@ #include "strutil.h" -#define DOUBLE_REPR_LENGTH 27 - static void double_fvalue_new(fvalue_t *fv) { @@ -72,38 +70,25 @@ val_from_unparsed(fvalue_t *fv, const char *s, gboolean allow_partial_value _U_, static int float_val_repr_len(fvalue_t *fv _U_, ftrepr_t rtype _U_, int field_display _U_) { - /* - * 1 character for a sign. - * 26 characters for a Really Big Number. - * XXX - is that platform-dependent? - * XXX - smaller for float than for double? - * XXX - can we compute it from FLT_DIG and the like? - */ - return DOUBLE_REPR_LENGTH; + return G_ASCII_DTOSTR_BUF_SIZE; } static void float_val_to_repr(fvalue_t *fv, ftrepr_t rtype _U_, int field_display _U_, char *buf, unsigned int size) { - g_snprintf(buf, size, "%." G_STRINGIFY(FLT_DIG) "g", fv->value.floating); + g_ascii_formatd(buf, size, "%." G_STRINGIFY(FLT_DIG) "g", fv->value.floating); } static int double_val_repr_len(fvalue_t *fv _U_, ftrepr_t rtype _U_, int field_display _U_) { - /* - * 1 character for a sign. - * 26 characters for a Really Big Number. - * XXX - is that platform-dependent? - * XXX - can we compute it from DBL_DIG and the like? - */ - return DOUBLE_REPR_LENGTH; + return G_ASCII_DTOSTR_BUF_SIZE; } static void double_val_to_repr(fvalue_t *fv, ftrepr_t rtype _U_, int field_display _U_, char *buf, unsigned int size) { - g_snprintf(buf, size, "%." G_STRINGIFY(DBL_DIG) "g", fv->value.floating); + g_ascii_formatd(buf, size, "%." G_STRINGIFY(DBL_DIG) "g", fv->value.floating); } static gboolean @@ -207,3 +192,16 @@ ftype_register_double(void) ftype_register(FT_FLOAT, &float_type); ftype_register(FT_DOUBLE, &double_type); } + +/* + * Editor modelines - https://www.wireshark.org/tools/modelines.html + * + * Local variables: + * c-basic-offset: 8 + * tab-width: 8 + * indent-tabs-mode: t + * End: + * + * vi: set shiftwidth=8 tabstop=8 noexpandtab: + * :indentSize=8:tabSize=8:noTabs=false: + */ -- cgit v1.2.3