Support creating empty arrays with cJSON_Create*Array().

This commit is contained in:
Zhixu Zhao 2021-12-14 00:05:39 +08:00
parent 203a0dec6f
commit 5da11d6bea
1 changed files with 4 additions and 4 deletions

View File

@ -2540,7 +2540,7 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateIntArray(const int *numbers, int count)
cJSON *p = NULL;
cJSON *a = NULL;
if ((count < 0) || (numbers == NULL))
if ((count < 0) || ((count > 0) && (numbers == NULL)))
{
return NULL;
}
@ -2580,7 +2580,7 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateFloatArray(const float *numbers, int count)
cJSON *p = NULL;
cJSON *a = NULL;
if ((count < 0) || (numbers == NULL))
if ((count < 0) || ((count > 0) && (numbers == NULL)))
{
return NULL;
}
@ -2620,7 +2620,7 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateDoubleArray(const double *numbers, int count)
cJSON *p = NULL;
cJSON *a = NULL;
if ((count < 0) || (numbers == NULL))
if ((count < 0) || ((count > 0) && (numbers == NULL)))
{
return NULL;
}
@ -2660,7 +2660,7 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateStringArray(const char *const *strings, int co
cJSON *p = NULL;
cJSON *a = NULL;
if ((count < 0) || (strings == NULL))
if ((count < 0) || ((count > 0) && (strings == NULL)))
{
return NULL;
}