diff options
author | Michael Mann <mmann78@netscape.net> | 2017-01-31 07:51:19 -0500 |
---|---|---|
committer | Michael Mann <mmann78@netscape.net> | 2017-01-31 17:08:47 +0000 |
commit | 51a30142251e377ec28eb8584c56386c2481d6c0 (patch) | |
tree | 4a4667a656f60327647805022e5811b6f2c42052 /epan/strutil.c | |
parent | 0165b8c40cfd6ca529408862095c1213bdf1ebd5 (diff) |
format_text_wmem -> format_text
All cases of the "original" format_text have been handled to add the
proper wmem allocator scope. Remove the "original" format_text
and replace it with one that has a wmem allocator as a parameter.
Change-Id: I278b93bcb4a17ff396413b75cd332f5fc2666719
Reviewed-on: https://code.wireshark.org/review/19884
Petri-Dish: Michael Mann <mmann78@netscape.net>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Michael Mann <mmann78@netscape.net>
Diffstat (limited to 'epan/strutil.c')
-rw-r--r-- | epan/strutil.c | 106 |
1 files changed, 1 insertions, 105 deletions
diff --git a/epan/strutil.c b/epan/strutil.c index d4cab96cb6..e32cfcaab9 100644 --- a/epan/strutil.c +++ b/epan/strutil.c @@ -144,111 +144,7 @@ get_token_len(const guchar *linep, const guchar *lineend, * characters as C-style escapes, and return a pointer to it. */ gchar * -format_text(const guchar *string, size_t len) -{ - static gchar *fmtbuf[3]; - static int fmtbuf_len[3]; - static int idx; - int column; - const guchar *stringend = string + len; - guchar c; - int i; - - idx = (idx + 1) % 3; - - /* - * Allocate the buffer if it's not already allocated. - */ - if (fmtbuf[idx] == NULL) { - fmtbuf[idx] = (gchar *)g_malloc(INITIAL_FMTBUF_SIZE); - fmtbuf_len[idx] = INITIAL_FMTBUF_SIZE; - } - column = 0; - while (string < stringend) { - /* - * Is there enough room for this character, if it expands to - * a backslash plus 3 octal digits (which is the most it can - * expand to), and also enough room for a terminating '\0'? - */ - if (column+3+1 >= fmtbuf_len[idx]) { - /* - * Double the buffer's size if it's not big enough. - * The size of the buffer starts at 128, so doubling its size - * adds at least another 128 bytes, which is more than enough - * for one more character plus a terminating '\0'. - */ - fmtbuf_len[idx] = fmtbuf_len[idx] * 2; - fmtbuf[idx] = (gchar *)g_realloc(fmtbuf[idx], fmtbuf_len[idx]); - } - c = *string++; - - if (g_ascii_isprint(c)) { - fmtbuf[idx][column] = c; - column++; - } else { - fmtbuf[idx][column] = '\\'; - column++; - switch (c) { - - case '\a': - fmtbuf[idx][column] = 'a'; - column++; - break; - - case '\b': - fmtbuf[idx][column] = 'b'; /* BS */ - column++; - break; - - case '\f': - fmtbuf[idx][column] = 'f'; /* FF */ - column++; - break; - - case '\n': - fmtbuf[idx][column] = 'n'; /* NL */ - column++; - break; - - case '\r': - fmtbuf[idx][column] = 'r'; /* CR */ - column++; - break; - - case '\t': - fmtbuf[idx][column] = 't'; /* tab */ - column++; - break; - - case '\v': - fmtbuf[idx][column] = 'v'; - column++; - break; - - default: - i = (c>>6)&03; - fmtbuf[idx][column] = i + '0'; - column++; - i = (c>>3)&07; - fmtbuf[idx][column] = i + '0'; - column++; - i = (c>>0)&07; - fmtbuf[idx][column] = i + '0'; - column++; - break; - } - } - } - fmtbuf[idx][column] = '\0'; - return fmtbuf[idx]; -} - -/* - * Given a string, generate a string from it that shows non-printable - * characters as C-style escapes, and return a pointer to it. - */ -gchar * -format_text_wmem(wmem_allocator_t* allocator, const guchar *string, size_t len) +format_text(wmem_allocator_t* allocator, const guchar *string, size_t len) { gchar *fmtbuf = (gchar*)wmem_alloc(allocator, INITIAL_FMTBUF_SIZE); int fmtbuf_len = INITIAL_FMTBUF_SIZE; |