Fix null pointer crash, closes #536 (#538)

This commit is contained in:
Alan Wang 2020-12-17 15:42:31 +08:00 committed by GitHub
parent 4100379a04
commit 7b6645794d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

44
cJSON.c
View File

@ -2548,12 +2548,8 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateIntArray(const int *numbers, int count)
}
a = cJSON_CreateArray();
if (!a)
{
return NULL;
}
for(i = 0; i < (size_t)count; i++)
for(i = 0; a && (i < (size_t)count); i++)
{
n = cJSON_CreateNumber(numbers[i]);
if (!n)
@ -2571,7 +2567,10 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateIntArray(const int *numbers, int count)
}
p = n;
}
a->child->prev = n;
if (a && a->child) {
a->child->prev = n;
}
return a;
}
@ -2589,12 +2588,8 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateFloatArray(const float *numbers, int count)
}
a = cJSON_CreateArray();
if (!a)
{
return NULL;
}
for(i = 0; i < (size_t)count; i++)
for(i = 0; a && (i < (size_t)count); i++)
{
n = cJSON_CreateNumber((double)numbers[i]);
if(!n)
@ -2612,7 +2607,10 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateFloatArray(const float *numbers, int count)
}
p = n;
}
a->child->prev = n;
if (a && a->child) {
a->child->prev = n;
}
return a;
}
@ -2630,12 +2628,8 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateDoubleArray(const double *numbers, int count)
}
a = cJSON_CreateArray();
if (!a)
{
return NULL;
}
for(i = 0; i < (size_t)count; i++)
for(i = 0; a && (i < (size_t)count); i++)
{
n = cJSON_CreateNumber(numbers[i]);
if(!n)
@ -2653,7 +2647,10 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateDoubleArray(const double *numbers, int count)
}
p = n;
}
a->child->prev = n;
if (a && a->child) {
a->child->prev = n;
}
return a;
}
@ -2671,12 +2668,8 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateStringArray(const char *const *strings, int co
}
a = cJSON_CreateArray();
if (!a)
{
return NULL;
}
for (i = 0; i < (size_t)count; i++)
for (i = 0; a && (i < (size_t)count); i++)
{
n = cJSON_CreateString(strings[i]);
if(!n)
@ -2694,8 +2687,11 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateStringArray(const char *const *strings, int co
}
p = n;
}
a->child->prev = n;
if (a && a->child) {
a->child->prev = n;
}
return a;
}