redlis-cli crash on non-printable chars

The debug version of isprint() raises an assert when the input value
is not EOF or in the range 0 through 0xFF, inclusive.
The trick is that the char value needs to be passed as unsigned,
before being converted to int.
This commit is contained in:
Alexis Campailla
2015-02-24 17:16:52 +01:00
parent a39e4ae65d
commit fe6fff14d1
+4
View File
@@ -771,7 +771,11 @@ sds sdscatrepr(sds s, const char *p, size_t len) {
case '\a': s = sdscatlen(s,"\\a",2); break;
case '\b': s = sdscatlen(s,"\\b",2); break;
default:
#ifdef _WIN32
if (isprint((unsigned char)*p))
#else
if (isprint(*p))
#endif
s = sdscatprintf(s,"%c",*p);
else
s = sdscatprintf(s,"\\x%02x",(unsigned char)*p);