summaryrefslogtreecommitdiff
path: root/epan/to_str.c
diff options
context:
space:
mode:
authorMichael Mann <mmann78@netscape.net>2015-01-07 08:29:35 -0500
committerMichael Mann <mmann78@netscape.net>2015-01-07 18:05:35 +0000
commit9cfe67fde61fa16cdf433cb152b5b22949648c64 (patch)
tree5f61b4cf38f1c1d90f73d90092de65194be60adb /epan/to_str.c
parent493f03b4200f96f45fadf3302b1d3bfb5a95b409 (diff)
downloadwireshark-9cfe67fde61fa16cdf433cb152b5b22949648c64.tar.gz
tvb_bytes_to_ep_str_punct -> tvb_bytes_to_str_punct
Also change bytestring_to_str to match bytes_to_ep_str_punct functionality (limiting byte string size) Change-Id: Idb958c7f0c203d103629469302b81fa922714f7e Reviewed-on: https://code.wireshark.org/review/6369 Reviewed-by: Michael Mann <mmann78@netscape.net>
Diffstat (limited to 'epan/to_str.c')
-rw-r--r--epan/to_str.c34
1 files changed, 20 insertions, 14 deletions
diff --git a/epan/to_str.c b/epan/to_str.c
index 4b77ddc2f8..4dfdddf099 100644
--- a/epan/to_str.c
+++ b/epan/to_str.c
@@ -155,6 +155,9 @@ bytes_to_hexstr_punct(char *out, const guint8 *ad, guint32 len, char punct)
return out;
}
+/* Max string length for displaying byte string. */
+#define MAX_BYTE_STR_LEN 48
+
/* Routine to convert a sequence of bytes to a hex string, one byte/two hex
* digits at at a time, with a specified punctuation character between
* the bytes.
@@ -166,7 +169,12 @@ const gchar *
bytestring_to_str(wmem_allocator_t *scope, const guint8 *ad, const guint32 len, const char punct)
{
gchar *buf;
- size_t buflen;
+ size_t buflen = len;
+ gchar *buf_ptr;
+ int truncated = 0;
+
+ if (!punct)
+ return bytes_to_str(scope, ad, len);
if (!ad)
REPORT_DISSECTOR_BUG("Null pointer passed to bytestring_to_str()");
@@ -174,25 +182,23 @@ bytestring_to_str(wmem_allocator_t *scope, const guint8 *ad, const guint32 len,
if (len == 0)
return wmem_strdup(scope, "");
- if (punct)
- buflen=len*3;
- else
- buflen=len*2 + 1;
+ buf=(gchar *)wmem_alloc(scope, MAX_BYTE_STR_LEN+3+1);
+ if (buflen > MAX_BYTE_STR_LEN/3) { /* bd_len > 16 */
+ truncated = 1;
+ buflen = MAX_BYTE_STR_LEN/3;
+ }
- buf=(gchar *)wmem_alloc(scope, buflen);
+ buf_ptr = bytes_to_hexstr_punct(buf, ad, buflen, punct); /* max MAX_BYTE_STR_LEN-1 bytes */
- if (punct)
- bytes_to_hexstr_punct(buf, ad, len, punct);
- else
- bytes_to_hexstr(buf, ad, len);
+ if (truncated) {
+ *buf_ptr++ = punct; /* 1 byte */
+ buf_ptr = g_stpcpy(buf_ptr, "..."); /* 3 bytes */
+ }
- buf[buflen-1] = '\0';
+ *buf_ptr = '\0';
return buf;
}
-/* Max string length for displaying byte string. */
-#define MAX_BYTE_STR_LEN 48
-
gchar *
bytes_to_ep_str(const guint8 *bd, int bd_len)
{