From a715292793538812e132405a18e2cbc947789403 Mon Sep 17 00:00:00 2001 From: "Anna (navi) Figueiredo Gomes" Date: Thu, 7 Mar 2024 21:37:55 +0100 Subject: json.h: add checks for json->type on foreach macro Signed-off-by: Anna (navi) Figueiredo Gomes --- include/json.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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; -- cgit v1.2.3