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)
{