aboutsummaryrefslogtreecommitdiff
path: root/src/json.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/json.c')
-rw-r--r--src/json.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/json.c b/src/json.c
index b7ad44a..d65eb2c 100644
--- a/src/json.c
+++ b/src/json.c
@@ -42,6 +42,21 @@ json_2nrealloc(void *p, size_t *pn, size_t s)
return newp;
}
+char const *
+json_strerror(int ec)
+{
+ static char *json_errstr[] = {
+ [JSON_E_NOERR] = "No error",
+ [JSON_E_NOMEM] = "Not enough memory",
+ [JSON_E_BADTOK] = "Unrecognized token",
+ [JSON_E_BADDELIM] = "Bad delimiter",
+ [JSON_E_BADSTRING] = "Malformed string"
+ };
+ if (ec < 0 || ec >= sizeof(json_errstr) / sizeof(json_errstr[0]))
+ return "Unknown error";
+ return json_errstr[ec];
+}
+
static void
json_format_writez(struct json_format *fmt, char const *str)
{
@@ -966,6 +981,11 @@ json_parse_string(char const *input, struct json_value **retval, char **endp)
break;
case json_object:
+ if (!ctx->key) {
+ json_value_free(val);
+ ecode = JSON_E_BADTOK;
+ goto err;
+ }
rc = json_object_set(ctx->obj,
ctx->key, val);
free(ctx->key);

Return to:

Send suggestions and report system problems to the System administrator.