mirror of
https://github.com/DaveGamble/cJSON.git
synced 2023-08-10 21:13:26 +03:00
fix null pointer dereferences found by coverity
This commit is contained in:
parent
2f712c7456
commit
9ed906758e
18
cJSON.c
18
cJSON.c
@ -1789,14 +1789,18 @@ static cJSON *create_reference(const cJSON *item)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Add item to array/object. */
|
/* Add item to array/object. */
|
||||||
void cJSON_AddItemToArray(cJSON *array, cJSON *item)
|
void cJSON_AddItemToArray(cJSON *array, cJSON *item)
|
||||||
{
|
{
|
||||||
cJSON *c = array->child;
|
cJSON *child = NULL;
|
||||||
if (!item)
|
|
||||||
|
if ((item == NULL) || (array == NULL))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!c)
|
|
||||||
|
child = array->child;
|
||||||
|
|
||||||
|
if (child == NULL)
|
||||||
{
|
{
|
||||||
/* list is empty, start new one */
|
/* list is empty, start new one */
|
||||||
array->child = item;
|
array->child = item;
|
||||||
@ -1804,11 +1808,11 @@ void cJSON_AddItemToArray(cJSON *array, cJSON *item)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* append to the end */
|
/* append to the end */
|
||||||
while (c->next)
|
while (child->next)
|
||||||
{
|
{
|
||||||
c = c->next;
|
child = child->next;
|
||||||
}
|
}
|
||||||
suffix_object(c, item);
|
suffix_object(child, item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -494,6 +494,12 @@ static int cJSONUtils_ApplyPatch(cJSON *object, cJSON *patch)
|
|||||||
int cJSONUtils_ApplyPatches(cJSON *object, cJSON *patches)
|
int cJSONUtils_ApplyPatches(cJSON *object, cJSON *patches)
|
||||||
{
|
{
|
||||||
int err = 0;
|
int err = 0;
|
||||||
|
|
||||||
|
if (patches == NULL)
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
if ((patches->type & 0xFF) != cJSON_Array)
|
if ((patches->type & 0xFF) != cJSON_Array)
|
||||||
{
|
{
|
||||||
/* malformed patches. */
|
/* malformed patches. */
|
||||||
@ -544,6 +550,11 @@ void cJSONUtils_AddPatchToArray(cJSON *array, const char *op, const char *path,
|
|||||||
|
|
||||||
static void cJSONUtils_CompareToPatch(cJSON *patches, const unsigned char *path, cJSON *from, cJSON *to)
|
static void cJSONUtils_CompareToPatch(cJSON *patches, const unsigned char *path, cJSON *from, cJSON *to)
|
||||||
{
|
{
|
||||||
|
if ((from == NULL) || (to == NULL))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if ((from->type & 0xFF) != (to->type & 0xFF))
|
if ((from->type & 0xFF) != (to->type & 0xFF))
|
||||||
{
|
{
|
||||||
cJSONUtils_GeneratePatch(patches, (const unsigned char*)"replace", path, 0, to);
|
cJSONUtils_GeneratePatch(patches, (const unsigned char*)"replace", path, 0, to);
|
||||||
|
Loading…
Reference in New Issue
Block a user