X-Git-Url: https://git.notmuchmail.org/git?p=notmuch;a=blobdiff_plain;f=json.c;h=817fc83a3de060eb954575138a7c2c50471982ea;hp=f90b0fa245324204347070d870ac22257e0d6f95;hb=76a2db3d7b92bc1a8be75f673dc384c46cf02fab;hpb=9eb360329929258fb243cfb5095989ba45391109 diff --git a/json.c b/json.c index f90b0fa2..817fc83a 100644 --- a/json.c +++ b/json.c @@ -57,13 +57,10 @@ json_quote_chararray(const void *ctx, const char *str, const size_t len) 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++; } @@ -80,7 +77,7 @@ json_quote_chararray(const void *ctx, const char *str, const size_t len) *ptr2++ = '\"'; for (loop = 0; loop < len; loop++) { - if (*ptr > 31 && *ptr != '\"' && *ptr != '\\') { + if ((unsigned char)(*ptr) > 31 && *ptr != '\"' && *ptr != '\\') { *ptr2++ = *ptr++; } else { *ptr2++ = '\\'; @@ -105,5 +102,8 @@ json_quote_chararray(const void *ctx, const char *str, const size_t len) char * json_quote_str(const void *ctx, const char *str) { + if (str == NULL) + str = ""; + return (json_quote_chararray (ctx, str, strlen (str))); }