fix potential NULL dereferences found by coverity

This commit is contained in:
Max Bruckner 2017-02-08 03:00:44 +01:00
parent 49b9336558
commit 4047de4f6e
2 changed files with 6 additions and 1 deletions

View File

@ -167,6 +167,11 @@ static const unsigned char *parse_number(cJSON *item, const unsigned char *num)
double number = 0; double number = 0;
unsigned char *endpointer = NULL; unsigned char *endpointer = NULL;
if (num == NULL)
{
return NULL;
}
number = strtod((const char*)num, (char**)&endpointer); number = strtod((const char*)num, (char**)&endpointer);
if ((num == endpointer) || (num == NULL)) if ((num == endpointer) || (num == NULL))
{ {

View File

@ -277,7 +277,7 @@ static cJSON *cJSONUtils_PatchDetach(cJSON *object, const unsigned char *path)
static int cJSONUtils_Compare(cJSON *a, cJSON *b) static int cJSONUtils_Compare(cJSON *a, cJSON *b)
{ {
if ((a->type & 0xFF) != (b->type & 0xFF)) if ((a == NULL) || (b == NULL) || ((a->type & 0xFF) != (b->type & 0xFF)))
{ {
/* mismatched type. */ /* mismatched type. */
return -1; return -1;