mirror of
https://github.com/DaveGamble/cJSON.git
synced 2023-08-10 21:13:26 +03:00
handle null pointers: cJSON_GetArraySize
This commit is contained in:
parent
56f2bc6f3e
commit
e9d1de24cf
20
cJSON.c
20
cJSON.c
@ -1653,17 +1653,25 @@ static cJSON_bool print_object(const cJSON * const item, printbuffer * const out
|
|||||||
/* Get Array size/item / object item. */
|
/* Get Array size/item / object item. */
|
||||||
CJSON_PUBLIC(int) cJSON_GetArraySize(const cJSON *array)
|
CJSON_PUBLIC(int) cJSON_GetArraySize(const cJSON *array)
|
||||||
{
|
{
|
||||||
cJSON *c = array->child;
|
cJSON *child = NULL;
|
||||||
size_t i = 0;
|
size_t size = 0;
|
||||||
while(c)
|
|
||||||
|
if (array == NULL)
|
||||||
{
|
{
|
||||||
i++;
|
return 0;
|
||||||
c = c->next;
|
}
|
||||||
|
|
||||||
|
child = array->child;
|
||||||
|
|
||||||
|
while(child != NULL)
|
||||||
|
{
|
||||||
|
size++;
|
||||||
|
child = child->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* FIXME: Can overflow here. Cannot be fixed without breaking the API */
|
/* FIXME: Can overflow here. Cannot be fixed without breaking the API */
|
||||||
|
|
||||||
return (int)i;
|
return (int)size;
|
||||||
}
|
}
|
||||||
|
|
||||||
static cJSON* get_array_item(const cJSON *array, size_t index)
|
static cJSON* get_array_item(const cJSON *array, size_t index)
|
||||||
|
Loading…
Reference in New Issue
Block a user