]> git.notmuchmail.org Git - notmuch/blobdiff - json.c
debian: bump gmime dependency to 2.6.7
[notmuch] / json.c
diff --git a/json.c b/json.c
index f90b0fa245324204347070d870ac22257e0d6f95..817fc83a3de060eb954575138a7c2c50471982ea 100644 (file)
--- 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)));
 }