diff options
author | Michael Mann <mmann78@netscape.net> | 2016-05-10 14:38:19 -0400 |
---|---|---|
committer | Michael Mann <mmann78@netscape.net> | 2016-05-10 22:48:39 +0000 |
commit | 931603c4b84a5e69e94e3bfd3c84332e664062ab (patch) | |
tree | bbf4641eaabecd860f88a7b04861a6e2a0653f89 /rawshark.c | |
parent | 82373315fdae92cf7161c0b3cdba6427273e55b9 (diff) |
rawshark: Have fvalue_to_string_repr just return allocated string representation.
Simplify use of fvalue_to_string_repr in rawshark by just having it
return an allocated string representation of a field value instead
of trying to find the right allocated buffer size to pass in.
This will also allow fvalue_to_string_repr to be converted to
exclusively return allocated strings and not accept a provided buffer.
Change-Id: I9996411dca4656d599b30ed415453d0207131824
Reviewed-on: https://code.wireshark.org/review/15342
Reviewed-by: Michael Mann <mmann78@netscape.net>
Diffstat (limited to 'rawshark.c')
-rw-r--r-- | rawshark.c | 23 |
1 files changed, 8 insertions, 15 deletions
diff --git a/rawshark.c b/rawshark.c index 567c704447..41ca4ba716 100644 --- a/rawshark.c +++ b/rawshark.c @@ -1164,10 +1164,10 @@ static void field_display_to_string(header_field_info *hfi, char* buf, int size) static gboolean print_field_value(field_info *finfo, int cmd_line_index) { header_field_info *hfinfo; - static char *fs_buf = NULL; - char *fs_ptr = fs_buf; + char *fs_buf = NULL; + char *fs_ptr = NULL; static GString *label_s = NULL; - int fs_buf_len = FIELD_STR_INIT_LEN, fs_len; + int fs_len; guint i; string_fmt_t *sf; guint32 uvalue; @@ -1178,11 +1178,6 @@ static gboolean print_field_value(field_info *finfo, int cmd_line_index) hfinfo = finfo->hfinfo; - if (!fs_buf) { - fs_buf = (char *)g_malloc(fs_buf_len + 1); - fs_ptr = fs_buf; - } - if (!label_s) { label_s = g_string_new(""); } @@ -1194,14 +1189,10 @@ static gboolean print_field_value(field_info *finfo, int cmd_line_index) * e.g: ip.hdr_len */ fs_len = fvalue_string_repr_len(&finfo->value, FTREPR_DFILTER, finfo->hfinfo->display); - while (fs_buf_len < fs_len) { - fs_buf_len *= 2; - fs_buf = (char *)g_realloc(fs_buf, fs_buf_len + 1); - fs_ptr = fs_buf; - } - fvalue_to_string_repr(&finfo->value, + fs_buf = fvalue_to_string_repr(&finfo->value, FTREPR_DFILTER, finfo->hfinfo->display, - fs_buf); + NULL); + fs_ptr = fs_buf; /* String types are quoted. Remove them. */ if (IS_FT_STRING(finfo->value.ftype->ftype) && fs_len > 2) { @@ -1289,12 +1280,14 @@ static gboolean print_field_value(field_info *finfo, int cmd_line_index) } } printf(" %d=\"%s\"", cmd_line_index, label_s->str); + g_free(fs_buf); return TRUE; } if(finfo->value.ftype->val_to_string_repr) { printf(" %d=\"%s\"", cmd_line_index, fs_ptr); + g_free(fs_buf); return TRUE; } |