summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnna (navi) Figueiredo Gomes <navi@vlhl.dev>2024-03-07 21:37:55 +0100
committerAnna (navi) Figueiredo Gomes <navi@vlhl.dev>2024-03-07 21:37:55 +0100
commita715292793538812e132405a18e2cbc947789403 (patch)
tree3310a50a0604af371e3280d4ee01196eb5a79a38
parente66039a4bdb809691ba326edf5f144fe786715cb (diff)
json.h: add checks for json->type on foreach macro
Signed-off-by: Anna (navi) Figueiredo Gomes <navi@vlhl.dev>
-rw-r--r--include/json.h2
1 files changed, 1 insertions, 1 deletions
diff --git a/include/json.h b/include/json.h
index 9257ff2..5245115 100644
--- a/include/json.h
+++ b/include/json.h
@@ -107,7 +107,7 @@ struct json *json_new_null(void);
char *json_print(struct json *json);
#define json_foreach(e, o) \
- for (e = o->children->items[0]; e; e = e->next)
+ for (e = json_is_object(o) || json_is_array(o) ? o->children->items[0] : NULL; e; e = e->next)
static inline bool json_is_object(struct json *json) {
return json && json->type == JSON_OBJECT;