Replace some val_to_str calls with the equivalent val_to_str_const calls (and

implement rval_to_str_const to do this). The format-strings didn't have any
parameter specifiers in them, so they were clearly never used (or they would
have blown up) but still a bug.

This is one of the first steps towards converting val_to_str and friends to
wmem. I'm honestly not sure what the best approach is for the API in this case:
the vast majority of usage is within dissectors, so just hard-coding packet
scope (the way they currently hard-code ep_ scope) doesn't look terrible, but
there are *some* uses in taps and other places that will need to be converted to
something else if we go that route. Adding a wmem_pool parameter just for the
uncommon case seems a bit like overkill, though perhaps it is the right thing to
do.

svn path=/trunk/; revision=52264
This commit is contained in:
Evan Huus 2013-09-29 12:44:50 +00:00
parent 640a45d707
commit c1dd5d3882
3 changed files with 28 additions and 8 deletions

View File

@ -544,6 +544,22 @@ rval_to_str(const guint32 val, const range_string *rs, const char *fmt)
return ep_strdup_printf(fmt, val);
}
/* Like val_to_str_const except for range_string */
const gchar *
rval_to_str_const(const guint32 val, const range_string *rs,
const char *unknown_str)
{
const gchar *ret = NULL;
DISSECTOR_ASSERT(unknown_str != NULL);
ret = try_rval_to_str(val, rs);
if(ret != NULL)
return ret;
return unknown_str;
}
/* Like try_val_to_str_idx except for range_string */
const gchar *
try_rval_to_str_idx(const guint32 val, const range_string *rs, gint *idx)

View File

@ -158,6 +158,10 @@ WS_DLL_PUBLIC
const gchar*
rval_to_str(const guint32 val, const range_string *rs, const char *fmt);
WS_DLL_PUBLIC
const gchar *
rval_to_str_const(const guint32 val, const range_string *rs, const char *unknown_str);
WS_DLL_PUBLIC
const gchar*
try_rval_to_str(const guint32 val, const range_string *rs);

View File

@ -1360,18 +1360,18 @@ static gboolean print_field_value(field_info *finfo, int cmd_line_index)
DISSECTOR_ASSERT(!hfinfo->bitmask);
svalue = fvalue_get_sinteger(&finfo->value);
if (hfinfo->display & BASE_RANGE_STRING) {
g_string_append(label_s, rval_to_str(svalue, RVALS(hfinfo->strings), "Unknown"));
g_string_append(label_s, rval_to_str_const(svalue, RVALS(hfinfo->strings), "Unknown"));
} else if (hfinfo->display & BASE_EXT_STRING) {
g_string_append(label_s, val_to_str_ext(svalue, (const value_string_ext *) hfinfo->strings, "Unknown"));
g_string_append(label_s, val_to_str_ext_const(svalue, (const value_string_ext *) hfinfo->strings, "Unknown"));
} else {
g_string_append(label_s, val_to_str(svalue, cVALS(hfinfo->strings), "Unknown"));
g_string_append(label_s, val_to_str_const(svalue, cVALS(hfinfo->strings), "Unknown"));
}
break;
case FT_INT64:
DISSECTOR_ASSERT(!hfinfo->bitmask);
svalue64 = (gint64)fvalue_get_integer64(&finfo->value);
if (hfinfo->display & BASE_VAL64_STRING) {
g_string_append(label_s, val64_to_str(svalue64, (const val64_string *)(hfinfo->strings), "Unknown"));
g_string_append(label_s, val64_to_str_const(svalue64, (const val64_string *)(hfinfo->strings), "Unknown"));
}
break;
case FT_UINT8:
@ -1380,18 +1380,18 @@ static gboolean print_field_value(field_info *finfo, int cmd_line_index)
case FT_UINT32:
uvalue = fvalue_get_uinteger(&finfo->value);
if (!hfinfo->bitmask && hfinfo->display & BASE_RANGE_STRING) {
g_string_append(label_s, rval_to_str(uvalue, RVALS(hfinfo->strings), "Unknown"));
g_string_append(label_s, rval_to_str_const(uvalue, RVALS(hfinfo->strings), "Unknown"));
} else if (hfinfo->display & BASE_EXT_STRING) {
g_string_append(label_s, val_to_str_ext(uvalue, (const value_string_ext *) hfinfo->strings, "Unknown"));
g_string_append(label_s, val_to_str_ext_const(uvalue, (const value_string_ext *) hfinfo->strings, "Unknown"));
} else {
g_string_append(label_s, val_to_str(uvalue, cVALS(hfinfo->strings), "Unknown"));
g_string_append(label_s, val_to_str_const(uvalue, cVALS(hfinfo->strings), "Unknown"));
}
break;
case FT_UINT64:
DISSECTOR_ASSERT(!hfinfo->bitmask);
uvalue64 = fvalue_get_integer64(&finfo->value);
if (hfinfo->display & BASE_VAL64_STRING) {
g_string_append(label_s, val64_to_str(uvalue64, (const val64_string *)(hfinfo->strings), "Unknown"));
g_string_append(label_s, val64_to_str_const(uvalue64, (const val64_string *)(hfinfo->strings), "Unknown"));
}
break;
default: