diff options
author | Guy Harris <guy@alum.mit.edu> | 2014-10-16 11:16:11 -0700 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2014-10-16 18:16:58 +0000 |
commit | 50add40a2da49178fd784b063e44d59208d40d02 (patch) | |
tree | 09f0df938983a1352f92ddf3a8325dd49a768f0f /epan | |
parent | 353f6258f92ed7f8787cc32cd92ac3d44aa88f21 (diff) |
Fix some more "char is unsigned" issues, and a possible "char is signed" one.
C neither guarantees that char is signed nor that it's unsigned. Make
the str_to_nibble tables arrays of gint8, to make sure they can hold
numbers between 0 and 15 as well as -1. Cast gchar to guchar, not int,
when using it as a subscript into that array, so that the subscripts are
in the range 0 to 255, not -128 to 127.
Change-Id: Ib85de5aa4e83ae9efd808c78ce3f86f45b4a3f2a
Reviewed-on: https://code.wireshark.org/review/4734
Reviewed-by: Guy Harris <guy@alum.mit.edu>
Diffstat (limited to 'epan')
-rw-r--r-- | epan/strutil.c | 8 | ||||
-rw-r--r-- | epan/wslua/wslua_internals.c | 8 |
2 files changed, 8 insertions, 8 deletions
diff --git a/epan/strutil.c b/epan/strutil.c index 0c598a7aa6..148eaf417c 100644 --- a/epan/strutil.c +++ b/epan/strutil.c @@ -594,14 +594,14 @@ gboolean hex_str_to_bytes_encoding(const gchar *hex_str, GByteArray *bytes, const gchar **endptr, const guint encoding, const gboolean fail_if_partial) { - gchar c, d; + gint8 c, d; guint8 val; const gchar *end = hex_str; gboolean retval = FALSE; gchar sep = -1; /* a map from ASCII hex chars to their value */ - static const gchar str_to_nibble[256] = { + static const gint8 str_to_nibble[256] = { -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, @@ -630,14 +630,14 @@ hex_str_to_bytes_encoding(const gchar *hex_str, GByteArray *bytes, const gchar * sep = get_valid_byte_sep(*(end+2), encoding); while (*end) { - c = str_to_nibble[(int)*end]; + c = str_to_nibble[(guchar)*end]; if (c < 0) { if (fail_if_partial) retval = FALSE; break; } ++end; - d = str_to_nibble[(int)*end]; + d = str_to_nibble[(guchar)*end]; if (d < 0) { if (fail_if_partial) retval = FALSE; break; diff --git a/epan/wslua/wslua_internals.c b/epan/wslua/wslua_internals.c index a742cbac5b..1ef53352bf 100644 --- a/epan/wslua/wslua_internals.c +++ b/epan/wslua/wslua_internals.c @@ -526,9 +526,9 @@ int wslua_hex2bin(lua_State* L, const char* data, const guint len, const gchar* luaL_Buffer b; guint i = 0; guint seplen = 0; - char c, d; + gint8 c, d; - static const char str_to_nibble[256] = { + static const gint8 str_to_nibble[256] = { -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, @@ -552,7 +552,7 @@ int wslua_hex2bin(lua_State* L, const char* data, const guint len, const gchar* luaL_buffinit(L, &b); for (i = 0; i < len;) { - c = str_to_nibble[(int)data[i]]; + c = str_to_nibble[(guchar)data[i]]; if (c < 0) { if (seplen && strncmp(&data[i], sep, seplen) == 0) { i += seplen; @@ -561,7 +561,7 @@ int wslua_hex2bin(lua_State* L, const char* data, const guint len, const gchar* break; } } - d = str_to_nibble[(int)data[++i]]; + d = str_to_nibble[(guchar)data[++i]]; if (d < 0) break; luaL_addchar(&b, (c * 16) + d); i++; |