summaryrefslogtreecommitdiff
path: root/json.c
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>2009-08-28 14:26:05 +0000
committerEric S. Raymond <esr@thyrsus.com>2009-08-28 14:26:05 +0000
commitb2ac538726a4ea27b47e105e9c1f2654e5d1d69d (patch)
tree6ac59bbe0a96a94bc3de93865963d7ec18acd735 /json.c
parentdbe646e2b3456c66f77876799fec610e3bbc631f (diff)
downloadgpsd-b2ac538726a4ea27b47e105e9c1f2654e5d1d69d.tar.gz
Optimize, and add some debugging.
Diffstat (limited to 'json.c')
-rw-r--r--json.c18
1 files changed, 11 insertions, 7 deletions
diff --git a/json.c b/json.c
index 8ce3268f..91cc3abf 100644
--- a/json.c
+++ b/json.c
@@ -185,6 +185,12 @@ static int json_internal_read_object(const char *cp, const struct json_attr_t *a
return JSON_ERR_BADATTR;
}
state = await_value;
+ if (cursor->type == string)
+ maxlen = cursor->len - 1;
+ else if (cursor->type == check)
+ maxlen = strlen(cursor->dflt.check);
+ else if (cursor->map != NULL)
+ maxlen = sizeof(valbuf)-1;
pval = valbuf;
} else if (pattr >= attrbuf + JSON_ATTR_MAX - 1) {
#ifdef JSONDEBUG
@@ -223,14 +229,8 @@ static int json_internal_read_object(const char *cp, const struct json_attr_t *a
}
break;
case in_val_string:
- if (cursor->type == string)
- maxlen = cursor->len - 1;
- else if (cursor->type == check)
- maxlen = strlen(cursor->dflt.check);
- else if (cursor->map != NULL)
- maxlen = sizeof(valbuf)-1;
if (*cp == '"') {
- *pval = '\0';
+ *pval++ = '\0';
#ifdef JSONDEBUG
(void) printf("Collected string value %s\n", valbuf);
#endif /* JSONDEBUG */
@@ -266,6 +266,9 @@ static int json_internal_read_object(const char *cp, const struct json_attr_t *a
if (strcmp(mp->name, valbuf) == 0) {
goto foundit;
}
+#ifdef JSONDEBUG
+ (void) printf("Invalid enumeated value string %s.\n", valbuf);
+#endif /* JSONDEBUG */
return JSON_ERR_BADENUM;
foundit:
(void)snprintf(valbuf, sizeof(valbuf), "%d", mp->value);
@@ -464,6 +467,7 @@ const char *json_error_string(int err)
"error while string parsing",
"check attribute not matched",
"can't support strings in parallel arrays",
+ "invalid enumerated value",
"other data conversion error",
};