cJSON_ConfigurationChangePrebufferSize

This commit is contained in:
Max Bruckner
2018-02-03 02:09:10 +01:00
parent 0474d4d85f
commit c4c52cfe58
3 changed files with 39 additions and 28 deletions

36
cJSON.c
View File

@@ -62,10 +62,6 @@
#define true ((cJSON_bool)1)
#define false ((cJSON_bool)0)
#ifndef SIZE_MAX
#define SIZE_MAX ((size_t)-1)
#endif
typedef struct {
const unsigned char *json;
size_t position;
@@ -2894,21 +2890,6 @@ CJSON_PUBLIC(cJSON_bool) cJSON_IsRaw(const cJSON * const item)
return (item->type & 0xFF) == cJSON_Raw;
}
static size_t get_size_from_number(const cJSON * const number)
{
if (number->valuedouble >= SIZE_MAX)
{
return SIZE_MAX;
}
if (number->valuedouble <= 0)
{
return 0;
}
return (size_t)number->valuedouble;
}
CJSON_PUBLIC(cJSON_Configuration) cJSON_CreateConfiguration(const cJSON * const json, const cJSON_Allocators * const allocators, void *allocator_userdata)
{
internal_configuration *configuration = NULL;
@@ -2949,12 +2930,6 @@ CJSON_PUBLIC(cJSON_Configuration) cJSON_CreateConfiguration(const cJSON * const
/* then overwrite with other options if they exist */
option = get_object_item(json, "buffer_size", &global_configuration);
if (cJSON_IsNumber(option))
{
configuration->buffer_size = get_size_from_number(option);
}
option = get_object_item(json, "format", &global_configuration);
if (cJSON_IsTrue(option))
{
@@ -3032,6 +3007,17 @@ CJSON_PUBLIC(cJSON_Configuration) cJSON_ConfigurationChangeParseEnd(cJSON_Config
return configuration;
}
CJSON_PUBLIC(cJSON_Configuration) cJSON_ConfigurationChangePrebufferSize(cJSON_Configuration configuration, const size_t buffer_size)
{
if ((configuration == NULL) || (buffer_size == 0))
{
return NULL;
}
((internal_configuration*)configuration)->buffer_size = buffer_size;
return configuration;
}
static cJSON_bool compare(const cJSON * const a, const cJSON * const b, const internal_configuration * const configuration)
{
if ((a == NULL) || (b == NULL) || ((a->type & 0xFF) != (b->type & 0xFF)) || cJSON_IsInvalid(a))