summaryrefslogtreecommitdiff
path: root/epan/strutil.c
diff options
context:
space:
mode:
authorMichael Mann <mmann78@netscape.net>2017-01-29 18:51:00 -0500
committerMichael Mann <mmann78@netscape.net>2017-01-30 02:25:45 +0000
commitf789c91a5ebbbefba51aa3da983fe836ebc860d6 (patch)
treece4a066bc1d1e8fe4a3bfc1f49e171d8aeda33d2 /epan/strutil.c
parent9365fd3d3a4cdac07d70bd77f7a42f3260b33b5e (diff)
downloadwireshark-f789c91a5ebbbefba51aa3da983fe836ebc860d6.tar.gz
Have format_text_wsp use wmem allocated memory.
format_text_wsp is fed into by tvb_format_text_wsp and tvb_format_stringzpad_wsp so those functions need to add a wmem allocated parameter as well. Most of the changes came from tvb_format_text_wsp and tvb_format_stringzpad_wsp being changed more so than format_text_wsp. Change-Id: I52214ca107016f0e96371a9a8430aa89336f91d7 Reviewed-on: https://code.wireshark.org/review/19851 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.c52
1 files changed, 21 insertions, 31 deletions
diff --git a/epan/strutil.c b/epan/strutil.c
index ad560699d6..c4a65849a4 100644
--- a/epan/strutil.c
+++ b/epan/strutil.c
@@ -250,25 +250,15 @@ format_text(const guchar *string, size_t len)
* which will be replaced by a space, and return a pointer to it.
*/
gchar *
-format_text_wsp(const guchar *string, size_t len)
+format_text_wsp(wmem_allocator_t* allocator, const guchar *string, size_t len)
{
- static gchar *fmtbuf[3];
- static int fmtbuf_len[3];
- static int idx;
+ gchar *fmtbuf = (gchar*)wmem_alloc(allocator, INITIAL_FMTBUF_SIZE);
+ int fmtbuf_len = INITIAL_FMTBUF_SIZE;
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) {
/*
@@ -276,80 +266,80 @@ format_text_wsp(const guchar *string, size_t len)
* 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]) {
+ if (column+3+1 >= fmtbuf_len) {
/*
* 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]);
+ fmtbuf_len *= 2;
+ fmtbuf = (gchar *)wmem_realloc(allocator, fmtbuf, fmtbuf_len);
}
c = *string++;
if (g_ascii_isprint(c)) {
- fmtbuf[idx][column] = c;
+ fmtbuf[column] = c;
column++;
} else if (g_ascii_isspace(c)) {
- fmtbuf[idx][column] = ' ';
+ fmtbuf[column] = ' ';
column++;
} else {
- fmtbuf[idx][column] = '\\';
+ fmtbuf[column] = '\\';
column++;
switch (c) {
case '\a':
- fmtbuf[idx][column] = 'a';
+ fmtbuf[column] = 'a';
column++;
break;
case '\b':
- fmtbuf[idx][column] = 'b'; /* BS */
+ fmtbuf[column] = 'b'; /* BS */
column++;
break;
case '\f':
- fmtbuf[idx][column] = 'f'; /* FF */
+ fmtbuf[column] = 'f'; /* FF */
column++;
break;
case '\n':
- fmtbuf[idx][column] = 'n'; /* NL */
+ fmtbuf[column] = 'n'; /* NL */
column++;
break;
case '\r':
- fmtbuf[idx][column] = 'r'; /* CR */
+ fmtbuf[column] = 'r'; /* CR */
column++;
break;
case '\t':
- fmtbuf[idx][column] = 't'; /* tab */
+ fmtbuf[column] = 't'; /* tab */
column++;
break;
case '\v':
- fmtbuf[idx][column] = 'v';
+ fmtbuf[column] = 'v';
column++;
break;
default:
i = (c>>6)&03;
- fmtbuf[idx][column] = i + '0';
+ fmtbuf[column] = i + '0';
column++;
i = (c>>3)&07;
- fmtbuf[idx][column] = i + '0';
+ fmtbuf[column] = i + '0';
column++;
i = (c>>0)&07;
- fmtbuf[idx][column] = i + '0';
+ fmtbuf[column] = i + '0';
column++;
break;
}
}
}
- fmtbuf[idx][column] = '\0';
- return fmtbuf[idx];
+ fmtbuf[column] = '\0';
+ return fmtbuf;
}
/*