cJSON_ParseWithOptions: Improve variable names and intent

This commit is contained in:
Max Bruckner 2017-03-21 20:18:03 +01:00
parent 99db5db9a4
commit 11131b9ced

22
cJSON.c
View File

@ -903,19 +903,19 @@ CJSON_PUBLIC(cJSON *) cJSON_ParseWithOpts(const char *value, const char **return
{ {
const unsigned char *end = NULL; const unsigned char *end = NULL;
/* use global error pointer if no specific one was given */ /* use global error pointer if no specific one was given */
const unsigned char **ep = return_parse_end ? (const unsigned char**)return_parse_end : &global_ep; const unsigned char **error_pointer = (return_parse_end != NULL) ? (const unsigned char**)return_parse_end : &global_ep;
cJSON *c = cJSON_New_Item(&global_hooks); cJSON *item = cJSON_New_Item(&global_hooks);
*ep = NULL; *error_pointer = NULL;
if (!c) /* memory fail */ if (item == NULL) /* memory fail */
{ {
return NULL; return NULL;
} }
end = parse_value(c, skip_whitespace((const unsigned char*)value), ep, &global_hooks); end = parse_value(item, skip_whitespace((const unsigned char*)value), error_pointer, &global_hooks);
if (!end) if (end == NULL)
{ {
/* parse failure. ep is set. */ /* parse failure. ep is set. */
cJSON_Delete(c); cJSON_Delete(item);
return NULL; return NULL;
} }
@ -923,10 +923,10 @@ CJSON_PUBLIC(cJSON *) cJSON_ParseWithOpts(const char *value, const char **return
if (require_null_terminated) if (require_null_terminated)
{ {
end = skip_whitespace(end); end = skip_whitespace(end);
if (*end) if (*end != '\0')
{ {
cJSON_Delete(c); cJSON_Delete(item);
*ep = end; *error_pointer = end;
return NULL; return NULL;
} }
} }
@ -935,7 +935,7 @@ CJSON_PUBLIC(cJSON *) cJSON_ParseWithOpts(const char *value, const char **return
*return_parse_end = (const char*)end; *return_parse_end = (const char*)end;
} }
return c; return item;
} }
/* Default options for cJSON_Parse */ /* Default options for cJSON_Parse */