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>
This commit is contained in:
Guy Harris 2014-10-16 11:16:11 -07:00
parent 353f6258f9
commit 50add40a2d
2 changed files with 8 additions and 8 deletions

View File

@ -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;

View File

@ -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++;