aboutsummaryrefslogtreecommitdiffstats
path: root/epan/proto.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2015-02-22 00:56:00 -0800
committerGuy Harris <guy@alum.mit.edu>2015-02-22 08:56:43 +0000
commitd1865e000ebedf49fc0d9f221a11d6af74360837 (patch)
tree69c12856da865970e93c9bf07704903c0195afd0 /epan/proto.c
parent1157aa8fd18ffad0476312e703757cfda41d2f48 (diff)
Make FT_{U}INT{40,48,56,64} handle BASE_CUSTOM.
Finish the job of handling integral values > 32 bits similarly to who we handle values 32 bits or less. In cases that "should not happen", and where we might *not* be executing in the context of a dissector (filling in the field label can be done lazily, being deferred to "print" time, and that doesn't happen in the context of a dissector), use g_assert_not_reached() rather than DISSECTOR_ASSERT_NOT_REACHED() - the latter throws an assertion that's not caught if we're not doing dissection, so we crash anyway. Bug: 10983 Change-Id: Ia81a0a4925394f99aa35193a333f3e9659a9b93d Reviewed-on: https://code.wireshark.org/review/7307 Reviewed-by: Guy Harris <guy@alum.mit.edu>
Diffstat (limited to 'epan/proto.c')
-rw-r--r--epan/proto.c108
1 files changed, 23 insertions, 85 deletions
diff --git a/epan/proto.c b/epan/proto.c
index 03b7429090..54db3cc7f3 100644
--- a/epan/proto.c
+++ b/epan/proto.c
@@ -174,9 +174,6 @@ static const char *hfinfo_number_value_format64(const header_field_info *hfinfo,
static const char *hfinfo_numeric_value_format(const header_field_info *hfinfo, char buf[32], guint32 value);
static const char *hfinfo_numeric_value_format64(const header_field_info *hfinfo, char buf[32], guint64 value);
-static const char* hfinfo_uint64_format(const header_field_info *hfinfo);
-static const char* hfinfo_int64_format(const header_field_info *hfinfo);
-
static proto_item *
proto_tree_add_node(proto_tree *tree, field_info *fi);
@@ -6659,38 +6656,39 @@ fill_label_number(field_info *fi, gchar *label_str, gboolean is_signed)
static void
fill_label_number64(field_info *fi, gchar *label_str, gboolean is_signed)
{
- const char *format = NULL;
header_field_info *hfinfo = fi->hfinfo;
guint64 value;
- char tmp[ITEM_LABEL_LENGTH+1];
- /* Pick the proper format string */
- if (is_signed) {
- format = hfinfo_int64_format(hfinfo);
+ char buf[32];
+ const char *out;
+
+ if (is_signed)
value = fvalue_get_sinteger64(&fi->value);
- } else {
- format = hfinfo_uint64_format(hfinfo);
+ else
value = fvalue_get_uinteger64(&fi->value);
- }
- /* Format the temporary string */
- if (IS_BASE_DUAL(hfinfo->display))
- g_snprintf(tmp, ITEM_LABEL_LENGTH, format, value, value);
- else
- g_snprintf(tmp, ITEM_LABEL_LENGTH, format, value);
+ /* Fill in the textual info */
+ if (hfinfo->display == BASE_CUSTOM) {
+ gchar tmp[ITEM_LABEL_LENGTH];
+ const custom_fmt_func_64_t fmtfunc64 = (const custom_fmt_func_64_t)hfinfo->strings;
- if (hfinfo->strings) {
+ DISSECTOR_ASSERT(fmtfunc64);
+ fmtfunc64(tmp, value);
+ label_fill(label_str, 0, hfinfo, tmp);
+ }
+ else if (hfinfo->strings) {
const char *val_str = hf_try_val64_to_str_const(value, hfinfo, "Unknown");
- if ((hfinfo->display & FIELD_DISPLAY_E_MASK) == BASE_NONE) {
+ out = hfinfo_number_vals_format64(hfinfo, buf, value);
+ if (out == NULL) /* BASE_NONE so don't put integer in descr */
label_fill(label_str, 0, hfinfo, val_str);
- }
- else {
- label_fill_descr(label_str, 0, hfinfo, val_str, tmp);
- }
+ else
+ label_fill_descr(label_str, 0, hfinfo, val_str, out);
}
else {
- label_fill(label_str, 0, hfinfo, tmp);
+ out = hfinfo_number_value_format64(hfinfo, buf, value);
+
+ label_fill(label_str, 0, hfinfo, out);
}
}
@@ -6830,8 +6828,7 @@ hfinfo_number_value_format_display(const header_field_info *hfinfo, int display,
return ptr;
default:
- DISSECTOR_ASSERT_NOT_REACHED();
- ;
+ g_assert_not_reached();
}
return ptr;
}
@@ -6871,8 +6868,7 @@ hfinfo_number_value_format_display64(const header_field_info *hfinfo, int displa
return ptr;
default:
- DISSECTOR_ASSERT_NOT_REACHED();
- ;
+ g_assert_not_reached();
}
return ptr;
}
@@ -7003,64 +6999,6 @@ hfinfo_number_vals_format64(const header_field_info *hfinfo, char buf[32], guint
return hfinfo_number_value_format_display64(hfinfo, display, buf, value);
}
-static const char *
-hfinfo_uint64_format(const header_field_info *hfinfo)
-{
- const char *format = NULL;
-
- /* Pick the proper format string */
- switch (hfinfo->display & FIELD_DISPLAY_E_MASK) {
- case BASE_DEC:
- format = "%" G_GINT64_MODIFIER "u";
- break;
- case BASE_DEC_HEX:
- format = "%" G_GINT64_MODIFIER "u (0x%016" G_GINT64_MODIFIER "x)";
- break;
- case BASE_OCT: /* I'm lazy */
- format = "%#" G_GINT64_MODIFIER "o";
- break;
- case BASE_HEX:
- format = "0x%016" G_GINT64_MODIFIER "x";
- break;
- case BASE_HEX_DEC:
- format = "0x%016" G_GINT64_MODIFIER "x (%" G_GINT64_MODIFIER "u)";
- break;
- default:
- DISSECTOR_ASSERT_NOT_REACHED();
- ;
- }
- return format;
-}
-
-static const char *
-hfinfo_int64_format(const header_field_info *hfinfo)
-{
- const char *format = NULL;
-
- /* Pick the proper format string */
- switch (hfinfo->display & FIELD_DISPLAY_E_MASK) {
- case BASE_DEC:
- format = "%" G_GINT64_MODIFIER "d";
- break;
- case BASE_DEC_HEX:
- format = "%" G_GINT64_MODIFIER "d (0x%016" G_GINT64_MODIFIER "x)";
- break;
- case BASE_OCT: /* I'm lazy */
- format = "%#" G_GINT64_MODIFIER "o";
- break;
- case BASE_HEX:
- format = "0x%016" G_GINT64_MODIFIER "x";
- break;
- case BASE_HEX_DEC:
- format = "0x%016" G_GINT64_MODIFIER "x (%" G_GINT64_MODIFIER "d)";
- break;
- default:
- DISSECTOR_ASSERT_NOT_REACHED();
- ;
- }
- return format;
-}
-
const char *
proto_registrar_get_name(const int n)
{