summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--json.c7
-rw-r--r--test_json.c9
2 files changed, 16 insertions, 0 deletions
diff --git a/json.c b/json.c
index 3f3278f7..5550f228 100644
--- a/json.c
+++ b/json.c
@@ -529,6 +529,13 @@ int json_read_array(const char *cp, const struct json_array_t *arr,
tp = arr->arr.strings.store;
arrcount = 0;
+
+ /* Check for empty array */
+ while (isspace(*cp))
+ cp++;
+ if (*cp == ']')
+ goto breakout;
+
for (offset = 0; offset < arr->maxlen; offset++) {
json_debug_trace((1, "Looking at %s\n", cp));
switch (arr->element_type) {
diff --git a/test_json.c b/test_json.c
index 2c365e6e..85059f83 100644
--- a/test_json.c
+++ b/test_json.c
@@ -206,6 +206,11 @@ static const struct json_attr_t json_attrs_8[] = {
{"foe", t_integer, .addr.integer = &foe, .map=enum_table},
{NULL},
};
+
+/* Case 9: Like case 6 but w/ an empty array */
+
+static const char *json_str9 = "{\"parts\":[]}";
+
/*@ +fullinitblock @*/
/* *INDENT-ON* */
@@ -303,6 +308,10 @@ int main(int argc UNUSED, char *argv[]UNUSED)
assert_integer("fie", fie, 6);
assert_integer("foe", foe, 14);
+ status = json_read_object(json_str9, json_attrs_6, NULL);
+ assert_case(9, status);
+ assert_integer("dumbcount", dumbcount, 0);
+
(void)fprintf(stderr, "succeeded.\n");
exit(0);