aboutsummaryrefslogtreecommitdiffstats
path: root/epan/address_types.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2015-02-26 20:16:22 -0800
committerGuy Harris <guy@alum.mit.edu>2015-02-27 04:16:57 +0000
commit9ac60ff0df25765612d219dcaa7fe1210f6e0bcd (patch)
treeae62965f7d5c7edd12b99c4e5ca45e8e88a8d2bc /epan/address_types.c
parent1e66e74fa26a2bc29e0162a3a8740a66cbb5f55f (diff)
address_to_string routines need to remember the beginning of the buffer.
Either they don't have a pointer into the buffer that they advance, in which case strlen(buf)+1 works just fine, or they do, in which case 1) they'd better save the pointer to the beginning of the buffer, so they can figure out how long the string is when they're done and 2) they don't need to use strlen(), they can just subtract the pointers. Bug: 11016 Change-Id: I81ce9d517336a15bd81f0c6225756ce5178ec6cf Reviewed-on: https://code.wireshark.org/review/7424 Reviewed-by: Guy Harris <guy@alum.mit.edu>
Diffstat (limited to 'epan/address_types.c')
-rw-r--r--epan/address_types.c55
1 files changed, 30 insertions, 25 deletions
diff --git a/epan/address_types.c b/epan/address_types.c
index 4304980018..e351653bf4 100644
--- a/epan/address_types.c
+++ b/epan/address_types.c
@@ -401,12 +401,13 @@ int ipv6_name_res_len(void)
static int ipx_to_str(const address* addr, gchar *buf, int buf_len _U_)
{
const guint8 *addrdata = (const guint8 *)addr->data;
+ gchar *bufp = buf;
- buf = bytes_to_hexstr(buf, &addrdata[0], 4); /* 8 bytes */
- *buf++ = '.'; /*1 byte */
- buf = bytes_to_hexstr(buf, &addrdata[4], 6); /* 12 bytes */
- *buf++ = '\0'; /* NULL terminate */
- return (int)(strlen(buf)+1);
+ bufp = bytes_to_hexstr(bufp, &addrdata[0], 4); /* 8 bytes */
+ *bufp++ = '.'; /*1 byte */
+ bufp = bytes_to_hexstr(bufp, &addrdata[4], 6); /* 12 bytes */
+ *bufp++ = '\0'; /* NULL terminate */
+ return (int)(bufp - buf);
}
static int ipx_str_len(const address* addr _U_)
@@ -427,13 +428,14 @@ static int ipx_len(void)
static int vines_to_str(const address* addr, gchar *buf, int buf_len _U_)
{
const guint8 *addr_data = (const guint8 *)addr->data;
+ gchar *bufp = buf;
- buf = dword_to_hex(buf, pntoh32(&addr_data[0])); /* 8 bytes */
- *buf++ = '.'; /* 1 byte */
- buf = word_to_hex(buf, pntoh16(&addr_data[4])); /* 4 bytes */
- *buf = '\0'; /* NULL terminate */
+ bufp = dword_to_hex(bufp, pntoh32(&addr_data[0])); /* 8 bytes */
+ *bufp++ = '.'; /* 1 byte */
+ bufp = word_to_hex(bufp, pntoh16(&addr_data[4])); /* 4 bytes */
+ *bufp++ = '\0'; /* NULL terminate */
- return (int)(strlen(buf)+1);
+ return (int)(bufp - buf);
}
static int vines_str_len(const address* addr _U_)
@@ -451,10 +453,12 @@ static int vines_len(void)
******************************************************************************/
static int fc_to_str(const address* addr, gchar *buf, int buf_len _U_)
{
- buf = bytes_to_hexstr_punct(buf, (const guint8 *)addr->data, 3, '.');
- *buf = '\0'; /* NULL terminate */
+ gchar *bufp = buf;
- return (int)(strlen(buf)+1);
+ bufp = bytes_to_hexstr_punct(bufp, (const guint8 *)addr->data, 3, '.');
+ *bufp++ = '\0'; /* NULL terminate */
+
+ return (int)(bufp - buf);
}
static int fc_str_len(const address* addr _U_)
@@ -643,18 +647,19 @@ static int usb_addr_str_len(const address* addr _U_)
static int ax25_addr_to_str(const address* addr, gchar *buf, int buf_len _U_)
{
const guint8 *addrdata = (const guint8 *)addr->data;
-
- *buf++ = printable_char_or_period(addrdata[0] >> 1);
- *buf++ = printable_char_or_period(addrdata[1] >> 1);
- *buf++ = printable_char_or_period(addrdata[2] >> 1);
- *buf++ = printable_char_or_period(addrdata[3] >> 1);
- *buf++ = printable_char_or_period(addrdata[4] >> 1);
- *buf++ = printable_char_or_period(addrdata[5] >> 1);
- *buf++ = '-';
- buf = uint_to_str_back(buf, (addrdata[6] >> 1) & 0x0f);
- *buf = '\0'; /* NULL terminate */
-
- return (int)(strlen(buf)+1);
+ gchar *bufp = buf;
+
+ *bufp++ = printable_char_or_period(addrdata[0] >> 1);
+ *bufp++ = printable_char_or_period(addrdata[1] >> 1);
+ *bufp++ = printable_char_or_period(addrdata[2] >> 1);
+ *bufp++ = printable_char_or_period(addrdata[3] >> 1);
+ *bufp++ = printable_char_or_period(addrdata[4] >> 1);
+ *bufp++ = printable_char_or_period(addrdata[5] >> 1);
+ *bufp++ = '-';
+ bufp = uint_to_str_back(bufp, (addrdata[6] >> 1) & 0x0f);
+ *bufp++ = '\0'; /* NULL terminate */
+
+ return (int)(bufp - buf);
}
static int ax25_addr_str_len(const address* addr _U_)