verify: always log IO in the order they are issued
[fio.git] / json.c
diff --git a/json.c b/json.c
index ea61af72c422ad575238eaef2f4b4b2153a471d2..cba370ab4bdc59f70c425f9cea38fd63f4e47829 100644 (file)
--- a/json.c
+++ b/json.c
@@ -63,24 +63,28 @@ static char *strdup_escape(const char *str)
        char *p, *ret;
        int escapes;
 
+       if (!strlen(str))
+               return NULL;
+
        escapes = 0;
        while ((input = strpbrk(input, "\\\"")) != NULL) {
                escapes++;
                input++;
        }
 
-       p = ret = malloc(strlen(str) + escapes);
+       p = ret = malloc(strlen(str) + escapes + 1);
        while (*str) {
                if (*str == '\\' || *str == '\"')
                        *p++ = '\\';
                *p++ = *str++;
        }
+       *p = '\0';
 
        return ret;
 }
 
 /*
- * Valid JSON strings must escape '"' and '/' with a preceeding '/'
+ * Valid JSON strings must escape '"' and '/' with a preceding '/'
  */
 static struct json_value *json_create_value_string(const char *str)
 {