size_t loop;
size_t required;
- if (len == 0)
- return (char *)"\"\"";
-
for (loop = 0, required = 0, ptr = str;
loop < len;
loop++, required++, ptr++) {
- if (*ptr < 32 || *ptr == '\"' || *ptr == '\\')
+ if ((unsigned char)(*ptr) < 32 || *ptr == '\"' || *ptr == '\\')
required++;
}
*ptr2++ = '\"';
for (loop = 0; loop < len; loop++) {
- if (*ptr > 31 && *ptr != '\"' && *ptr != '\\') {
+ if ((unsigned char)(*ptr) > 31 && *ptr != '\"' && *ptr != '\\') {
*ptr2++ = *ptr++;
} else {
*ptr2++ = '\\';
char *
json_quote_str(const void *ctx, const char *str)
{
+ if (str == NULL)
+ str = "";
+
return (json_quote_chararray (ctx, str, strlen (str)));
}