diff options
| author | David Lamparter <equinox@diac24.net> | 2019-08-06 16:54:52 +0200 |
|---|---|---|
| committer | David Lamparter <equinox@diac24.net> | 2019-08-06 16:54:52 +0200 |
| commit | fefa5e0ff5af98d8258987e21422243926ee2b3c (patch) | |
| tree | 05ad830d4a48048156689b15a5c84df124964cb6 /lib/log.c | |
| parent | 7040d52aafca16fb0048c1712a919d8209c54dc9 (diff) | |
*: fix ctype (isalpha & co.) casts
The correct cast for these is (unsigned char), because "char" could be
signed and thus have some negative value. isalpha & co. expect an int
arg that is positive, i.e. 0-255. So we need to cast to (unsigned char)
when calling any of these.
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
Diffstat (limited to 'lib/log.c')
| -rw-r--r-- | lib/log.c | 13 |
1 files changed, 6 insertions, 7 deletions
@@ -1269,6 +1269,7 @@ void zlog_hexdump(const void *mem, unsigned int len) size_t bs = ((len / 8) + 1) * 53 + 1; char buf[bs]; char *s = buf; + const unsigned char *memch = mem; memset(buf, 0, sizeof(buf)); @@ -1277,12 +1278,11 @@ void zlog_hexdump(const void *mem, unsigned int len) /* print offset */ if (i % columns == 0) s += snprintf(s, bs - (s - buf), - "0x%016lx: ", (unsigned long)mem + i); + "0x%016lx: ", (unsigned long)memch + i); /* print hex data */ if (i < len) - s += snprintf(s, bs - (s - buf), "%02x ", - 0xFF & ((const char *)mem)[i]); + s += snprintf(s, bs - (s - buf), "%02x ", memch[i]); /* end of block, just aligning for ASCII dump */ else @@ -1294,10 +1294,9 @@ void zlog_hexdump(const void *mem, unsigned int len) /* end of block not really printing */ if (j >= len) s += snprintf(s, bs - (s - buf), " "); - else if (isprint((int)((const char *)mem)[j])) - s += snprintf( - s, bs - (s - buf), "%c", - 0xFF & ((const char *)mem)[j]); + else if (isprint(memch[j])) + s += snprintf(s, bs - (s - buf), "%c", + memch[j]); else /* other char */ s += snprintf(s, bs - (s - buf), "."); } |
