json_array_len will now fail if the passed in json is not an array

This commit is contained in:
Sara 2023-10-06 23:44:15 +02:00
parent 0c9e840986
commit 883d72ff99

View file

@ -169,7 +169,7 @@ cJSON* load_json_from_file(const char* filename) {
} }
size_t json_array_len(cJSON* json) { size_t json_array_len(cJSON* json) {
ASSERT_RETURN(!cJSON_IsArray(json), 0, "Tried to get the length of a non-array json element."); ASSERT_RETURN(cJSON_IsArray(json), 0, "Tried to get the length of a non-array json element.");
size_t len = 0; size_t len = 0;
cJSON* itr; cJSON* itr;
cJSON_ArrayForEach(itr, json) { cJSON_ArrayForEach(itr, json) {