Convert more time_to_str functions to wmem

Change-Id: Ibaae0e79935dc62f12f713f2df5b57d0f3f799b9
Reviewed-on: https://code.wireshark.org/review/2254
Reviewed-by: Evan Huus <eapache@gmail.com>
This commit is contained in:
Evan Huus 2014-06-16 10:54:20 -07:00
parent 9301c5b605
commit e0aabd97d8
7 changed files with 60 additions and 34 deletions

View File

@ -1431,7 +1431,7 @@ bootp_handle_basic_types(packet_info *pinfo, proto_tree *tree, proto_item *item,
time_u_secs = tvb_get_ntohl(tvb, offset);
proto_tree_add_uint_format_value(tree, *hf,
tvb, offset, 4, time_u_secs, "(%us) %s", time_u_secs,
((time_u_secs == 0xffffffff) ? "infinity" : time_secs_to_ep_str_unsigned(time_u_secs)));
((time_u_secs == 0xffffffff) ? "infinity" : time_secs_to_str_unsigned(wmem_packet_scope(), time_u_secs)));
}
else if (hf_default->time_in_u_secs != NULL)
proto_tree_add_item(tree, *hf_default->time_in_u_secs, tvb, offset, 4, ENC_BIG_ENDIAN);

View File

@ -1080,7 +1080,7 @@ ipmi_add_timestamp(proto_tree *tree, gint hf, tvbuff_t *tvb, guint offset)
} else if (ts <= 0x20000000) {
proto_tree_add_uint_format_value(tree, hf, tvb, offset, 4,
ts, "%s since SEL device's initialization",
time_secs_to_ep_str_unsigned(ts));
time_secs_to_str_unsigned(wmem_packet_scope(), ts));
} else {
proto_tree_add_uint_format_value(tree, hf, tvb, offset, 4,
ts, "%s", abs_time_secs_to_str(wmem_packet_scope(), ts, ABSOLUTE_TIME_UTC, TRUE));

View File

@ -1025,7 +1025,7 @@ tsn_tree(sctp_tsn_t *t, proto_item *tsn_item, packet_info *pinfo,
(*r)->framenum,
"This TSN was retransmitted in frame %u (%s seconds after this frame)",
(*r)->framenum,
rel_time_to_secs_ep_str(&rto));
rel_time_to_secs_str(wmem_packet_scope(), &rto));
PROTO_ITEM_SET_GENERATED(pi);
r = &(*r)->next;
}

View File

@ -352,15 +352,22 @@ static int
relative_val_repr_len(fvalue_t *fv, ftrepr_t rtype _U_)
{
gchar *rep;
int ret;
rep = rel_time_to_secs_ep_str(&fv->value.time);
return (int)strlen(rep);
rep = rel_time_to_secs_str(NULL, &fv->value.time);
ret = (int)strlen(rep);
wmem_free(NULL, rep);
return ret;
}
static void
relative_val_to_repr(fvalue_t *fv, ftrepr_t rtype _U_, char *buf)
{
strcpy(buf, rel_time_to_secs_ep_str(&fv->value.time));
gchar *rep;
rep = rel_time_to_secs_str(NULL, &fv->value.time);
strcpy(buf, rep);
wmem_free(NULL, rep);
}
void
@ -455,3 +462,16 @@ ftype_register_time(void)
ftype_register(FT_ABSOLUTE_TIME, &abstime_type);
ftype_register(FT_RELATIVE_TIME, &reltime_type);
}
/*
* Editor modelines - http://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:
*/

View File

@ -4085,6 +4085,7 @@ proto_custom_set(proto_tree* tree, const int field_id, gint occurrence,
const char *hf_str_val;
char number_buf[32];
const char *number_out;
char *tmpbuf;
g_assert(field_id >= 0);
@ -4171,16 +4172,19 @@ proto_custom_set(proto_tree* tree, const int field_id, gint occurrence,
break;
case FT_ABSOLUTE_TIME:
tmpbuf = abs_time_to_str(NULL, (const nstime_t *)fvalue_get(&finfo->value), (absolute_time_display_e)hfinfo->display, TRUE);
offset_r += protoo_strlcpy(result+offset_r,
abs_time_to_str(wmem_packet_scope(), (const nstime_t *)fvalue_get(&finfo->value),
(absolute_time_display_e)hfinfo->display, TRUE),
tmpbuf,
size-offset_r);
wmem_free(NULL, tmpbuf);
break;
case FT_RELATIVE_TIME:
tmpbuf = rel_time_to_secs_str(NULL, (const nstime_t *)fvalue_get(&finfo->value));
offset_r += protoo_strlcpy(result+offset_r,
rel_time_to_secs_ep_str((const nstime_t *)fvalue_get(&finfo->value)),
tmpbuf,
size-offset_r);
wmem_free(NULL, tmpbuf);
break;
case FT_BOOLEAN:
@ -5748,6 +5752,7 @@ proto_item_fill_label(field_info *fi, gchar *label_str)
guint32 n_addr; /* network-order IPv4 address */
const gchar *name;
address addr;
char *tmp;
if (!fi) {
if (label_str)
@ -5828,15 +5833,16 @@ proto_item_fill_label(field_info *fi, gchar *label_str)
break;
case FT_ABSOLUTE_TIME:
label_fill(label_str, 0, hfinfo,
abs_time_to_str(wmem_packet_scope(), (const nstime_t *)fvalue_get(&fi->value),
(absolute_time_display_e)hfinfo->display, TRUE));
tmp = abs_time_to_str(NULL, (const nstime_t *)fvalue_get(&fi->value), (absolute_time_display_e)hfinfo->display, TRUE);
label_fill(label_str, 0, hfinfo, tmp);
wmem_free(NULL, tmp);
break;
case FT_RELATIVE_TIME:
tmp = rel_time_to_secs_str(NULL, (const nstime_t *)fvalue_get(&fi->value));
g_snprintf(label_str, ITEM_LABEL_LENGTH,
"%s: %s seconds", hfinfo->name,
rel_time_to_secs_ep_str((const nstime_t *)fvalue_get(&fi->value)));
"%s: %s seconds", hfinfo->name, tmp);
wmem_free(NULL, tmp);
break;
case FT_IPXNET:

View File

@ -426,8 +426,8 @@ time_secs_to_str(wmem_allocator_t *scope, const gint32 time_val)
}
static void
time_secs_to_ep_str_buf_unsigned(guint32 time_val, const guint32 frac, const gboolean is_nsecs,
emem_strbuf_t *buf)
time_secs_to_str_buf_unsigned(guint32 time_val, const guint32 frac, const gboolean is_nsecs,
wmem_strbuf_t *buf)
{
int hours, mins, secs;
gboolean do_comma = FALSE;
@ -440,42 +440,42 @@ time_secs_to_ep_str_buf_unsigned(guint32 time_val, const guint32 frac, const gbo
time_val /= 24;
if (time_val != 0) {
ep_strbuf_append_printf(buf, "%u day%s", time_val, PLURALIZE(time_val));
wmem_strbuf_append_printf(buf, "%u day%s", time_val, PLURALIZE(time_val));
do_comma = TRUE;
}
if (hours != 0) {
ep_strbuf_append_printf(buf, "%s%u hour%s", COMMA(do_comma), hours, PLURALIZE(hours));
wmem_strbuf_append_printf(buf, "%s%u hour%s", COMMA(do_comma), hours, PLURALIZE(hours));
do_comma = TRUE;
}
if (mins != 0) {
ep_strbuf_append_printf(buf, "%s%u minute%s", COMMA(do_comma), mins, PLURALIZE(mins));
wmem_strbuf_append_printf(buf, "%s%u minute%s", COMMA(do_comma), mins, PLURALIZE(mins));
do_comma = TRUE;
}
if (secs != 0 || frac != 0) {
if (frac != 0) {
if (is_nsecs)
ep_strbuf_append_printf(buf, "%s%u.%09u seconds", COMMA(do_comma), secs, frac);
wmem_strbuf_append_printf(buf, "%s%u.%09u seconds", COMMA(do_comma), secs, frac);
else
ep_strbuf_append_printf(buf, "%s%u.%03u seconds", COMMA(do_comma), secs, frac);
wmem_strbuf_append_printf(buf, "%s%u.%03u seconds", COMMA(do_comma), secs, frac);
} else
ep_strbuf_append_printf(buf, "%s%u second%s", COMMA(do_comma), secs, PLURALIZE(secs));
wmem_strbuf_append_printf(buf, "%s%u second%s", COMMA(do_comma), secs, PLURALIZE(secs));
}
}
gchar *
time_secs_to_ep_str_unsigned(const guint32 time_val)
time_secs_to_str_unsigned(wmem_allocator_t *scope, const guint32 time_val)
{
emem_strbuf_t *buf;
buf=ep_strbuf_sized_new(TIME_SECS_LEN+1, TIME_SECS_LEN+1);
wmem_strbuf_t *buf;
if (time_val == 0) {
ep_strbuf_append(buf, "0 seconds");
return buf->str;
return wmem_strdup(scope, "0 seconds");
}
time_secs_to_ep_str_buf_unsigned(time_val, 0, FALSE, buf);
return buf->str;
buf = wmem_strbuf_sized_new(scope, TIME_SECS_LEN+1, TIME_SECS_LEN+1);
time_secs_to_str_buf_unsigned(time_val, 0, FALSE, buf);
return wmem_strbuf_finalize(buf);
}
@ -905,11 +905,11 @@ rel_time_to_str(wmem_allocator_t *scope, const nstime_t *rel_time)
* Display a relative time as seconds.
*/
gchar *
rel_time_to_secs_ep_str(const nstime_t *rel_time)
rel_time_to_secs_str(wmem_allocator_t *scope, const nstime_t *rel_time)
{
gchar *buf;
buf=(gchar *)ep_alloc(REL_TIME_SECS_LEN);
buf=(gchar *)wmem_alloc(scope, REL_TIME_SECS_LEN);
display_signed_time(buf, REL_TIME_SECS_LEN, (gint32) rel_time->secs,
rel_time->nsecs, TO_STR_TIME_RES_T_NSECS);

View File

@ -76,7 +76,7 @@ extern gchar* tvb_vines_addr_to_str(tvbuff_t *tvb, const gint offset);
WS_DLL_PUBLIC gchar* eui64_to_str(const guint64 ad);
WS_DLL_PUBLIC gchar* tvb_eui64_to_str(tvbuff_t *tvb, const gint offset, const guint encoding);
WS_DLL_PUBLIC gchar* time_secs_to_str(wmem_allocator_t *scope, const gint32 time_val);
gchar* time_secs_to_ep_str_unsigned(const guint32);
gchar* time_secs_to_str_unsigned(wmem_allocator_t *scope, const guint32);
WS_DLL_PUBLIC gchar* time_msecs_to_str(wmem_allocator_t *scope, gint32 time_val);
WS_DLL_PUBLIC gchar* abs_time_to_str(wmem_allocator_t *scope, const nstime_t*, const absolute_time_display_e fmt,
gboolean show_zone);
@ -88,7 +88,7 @@ WS_DLL_PUBLIC void display_epoch_time(gchar *, int, const time_t, gint32, const
extern void guint32_to_str_buf(guint32 u, gchar *buf, int buf_len);
WS_DLL_PUBLIC gchar* rel_time_to_str(wmem_allocator_t *scope, const nstime_t*);
WS_DLL_PUBLIC gchar* rel_time_to_secs_ep_str(const nstime_t*);
WS_DLL_PUBLIC gchar* rel_time_to_secs_str(wmem_allocator_t *scope, const nstime_t*);
WS_DLL_PUBLIC gchar* guid_to_ep_str(const e_guid_t*);
gchar* guid_to_str_buf(const e_guid_t*, gchar*, int);