Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix null pointer crash, closes #536 #538

Merged
merged 1 commit into from
Dec 17, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 20 additions & 24 deletions cJSON.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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;
}
Expand All @@ -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)
Expand All @@ -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;
}
Expand All @@ -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)
Expand All @@ -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;
}
Expand All @@ -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)
Expand All @@ -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;
}

Expand Down