diff options
author | Guy Harris <guy@alum.mit.edu> | 2002-12-10 07:39:48 +0000 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2002-12-10 07:39:48 +0000 |
commit | 8e1a648203df2278a91acb76024da7e68a1b4398 (patch) | |
tree | 2e3866911d8e1e98fac942254b3ad8eacc9ee428 /epan/to_str.c | |
parent | 9711eebb5b374fa6cec2d19a0147c2d6a9b53908 (diff) | |
download | wireshark-8e1a648203df2278a91acb76024da7e68a1b4398.tar.gz wireshark-8e1a648203df2278a91acb76024da7e68a1b4398.tar.bz2 wireshark-8e1a648203df2278a91acb76024da7e68a1b4398.zip |
Fix the formal argument list to "bytestring_to_str()" to match the
changes to the actual argument lists in the calls (putting the byte
string length after the byte string pointer).
Make the byte string length actually be the length, not the length - 1.
Use a #define for the longest byte string it can handle, and put in a
"g_assert()" to check the sanity of that length.
svn path=/trunk/; revision=6774
Diffstat (limited to 'epan/to_str.c')
-rw-r--r-- | epan/to_str.c | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/epan/to_str.c b/epan/to_str.c index 591f0f1ee6..9fa80ce868 100644 --- a/epan/to_str.c +++ b/epan/to_str.c @@ -1,7 +1,7 @@ /* to_str.c * Routines for utilities to convert various other types to strings. * - * $Id: to_str.c,v 1.21 2002/12/09 21:34:58 guy Exp $ + * $Id: to_str.c,v 1.22 2002/12/10 07:39:48 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@ethereal.com> @@ -63,16 +63,19 @@ #include <stdio.h> #include <time.h> +#define MAX_BYTESTRING_LEN 6 + /* 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. + * the bytes. The sequence of bytes must be no longer than + * MAX_BYTESTRING_LEN. * * If punct is '\0', no punctuation is applied (and thus - * the resulting string is 5 bytes shorter) + * the resulting string is (len-1) bytes shorter) */ static gchar * -bytestring_to_str(const guint8 *ad, char punct, guint32 len) { - static gchar str[3][18]; +bytestring_to_str(const guint8 *ad, guint32 len, char punct) { + static gchar str[3][MAX_BYTESTRING_LEN*3]; static gchar *cur; gchar *p; int i; @@ -87,6 +90,9 @@ bytestring_to_str(const guint8 *ad, char punct, guint32 len) { { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' }; + g_assert(len > 0 && len <= MAX_BYTESTRING_LEN); + len--; + if (cur == &str[0][0]) { cur = &str[1][0]; } else if (cur == &str[1][0]) { @@ -118,7 +124,7 @@ bytestring_to_str(const guint8 *ad, char punct, guint32 len) { gchar * ether_to_str(const guint8 *ad) { - return bytestring_to_str(ad, 5, ':'); + return bytestring_to_str(ad, 6, ':'); } gchar * @@ -205,7 +211,7 @@ ipx_addr_to_str(guint32 net, const guint8 *ad) } else { sprintf(cur, "%s.%s", get_ipxnet_name(net), - bytestring_to_str(ad, 5, '\0')); + bytestring_to_str(ad, 6, '\0')); } return cur; } @@ -544,7 +550,7 @@ rel_time_to_secs_str(nstime_t *rel_time) gchar * fc_to_str(const guint8 *ad) { - return bytestring_to_str (ad, 2, '.'); + return bytestring_to_str (ad, 3, '.'); } gchar * |