Replace 0 with more expressive NULL or '\0'

This commit is contained in:
Max Bruckner
2016-11-13 17:45:40 +07:00
parent d47339e274
commit a5ff796c20
2 changed files with 120 additions and 120 deletions

200
cJSON.c
View File

@ -66,7 +66,7 @@ static int cJSON_strcasecmp(const char *s1, const char *s2)
} }
for(; tolower(*(const unsigned char *)s1) == tolower(*(const unsigned char *)s2); ++s1, ++s2) for(; tolower(*(const unsigned char *)s1) == tolower(*(const unsigned char *)s2); ++s1, ++s2)
{ {
if (*s1 == 0) if (*s1 == '\0')
{ {
return 0; return 0;
} }
@ -86,7 +86,7 @@ static char* cJSON_strdup(const char* str)
len = strlen(str) + 1; len = strlen(str) + 1;
if (!(copy = (char*)cJSON_malloc(len))) if (!(copy = (char*)cJSON_malloc(len)))
{ {
return 0; return NULL;
} }
memcpy(copy, str, len); memcpy(copy, str, len);
@ -113,7 +113,7 @@ static cJSON *cJSON_New_Item(void)
cJSON* node = (cJSON*)cJSON_malloc(sizeof(cJSON)); cJSON* node = (cJSON*)cJSON_malloc(sizeof(cJSON));
if (node) if (node)
{ {
memset(node, 0, sizeof(cJSON)); memset(node, '\0', sizeof(cJSON));
} }
return node; return node;
@ -248,7 +248,7 @@ static char* ensure(printbuffer *p, int needed)
int newsize; int newsize;
if (!p || !p->buffer) if (!p || !p->buffer)
{ {
return 0; return NULL;
} }
needed += p->offset; needed += p->offset;
if (needed <= p->length) if (needed <= p->length)
@ -262,9 +262,9 @@ static char* ensure(printbuffer *p, int needed)
{ {
cJSON_free(p->buffer); cJSON_free(p->buffer);
p->length = 0; p->length = 0;
p->buffer = 0; p->buffer = NULL;
return 0; return NULL;
} }
if (newbuffer) if (newbuffer)
{ {
@ -293,7 +293,7 @@ static int update(const printbuffer *p)
/* Render the number nicely from the given item into a string. */ /* Render the number nicely from the given item into a string. */
static char *print_number(const cJSON *item, printbuffer *p) static char *print_number(const cJSON *item, printbuffer *p)
{ {
char *str = 0; char *str = NULL;
double d = item->valuedouble; double d = item->valuedouble;
/* special case for 0. */ /* special case for 0. */
if (d == 0) if (d == 0)
@ -478,7 +478,7 @@ static const char *parse_string(cJSON *item, const char *str, const char **ep)
if (*str != '\"') if (*str != '\"')
{ {
*ep = str; *ep = str;
return 0; return NULL;
} }
while ((*end_ptr != '\"') && *end_ptr && ++len) while ((*end_ptr != '\"') && *end_ptr && ++len)
@ -488,7 +488,7 @@ static const char *parse_string(cJSON *item, const char *str, const char **ep)
if (*end_ptr == '\0') if (*end_ptr == '\0')
{ {
/* prevent buffer overflow when last input character is a backslash */ /* prevent buffer overflow when last input character is a backslash */
return 0; return NULL;
} }
/* Skip escaped quotes. */ /* Skip escaped quotes. */
end_ptr++; end_ptr++;
@ -499,7 +499,7 @@ static const char *parse_string(cJSON *item, const char *str, const char **ep)
out = (char*)cJSON_malloc(len + 1); out = (char*)cJSON_malloc(len + 1);
if (!out) if (!out)
{ {
return 0; return NULL;
} }
item->valuestring = out; /* assign here so out will be deleted during cJSON_Delete() later */ item->valuestring = out; /* assign here so out will be deleted during cJSON_Delete() later */
item->type = cJSON_String; item->type = cJSON_String;
@ -547,13 +547,13 @@ static const char *parse_string(cJSON *item, const char *str, const char **ep)
{ {
/* invalid */ /* invalid */
*ep = str; *ep = str;
return 0; return NULL;
} }
/* check for invalid. */ /* check for invalid. */
if (((uc >= 0xDC00) && (uc <= 0xDFFF)) || (uc == 0)) if (((uc >= 0xDC00) && (uc <= 0xDFFF)) || (uc == 0))
{ {
*ep = str; *ep = str;
return 0; return NULL;
} }
/* UTF16 surrogate pairs. */ /* UTF16 surrogate pairs. */
@ -563,13 +563,13 @@ static const char *parse_string(cJSON *item, const char *str, const char **ep)
{ {
/* invalid */ /* invalid */
*ep = str; *ep = str;
return 0; return NULL;
} }
if ((ptr[1] != '\\') || (ptr[2] != 'u')) if ((ptr[1] != '\\') || (ptr[2] != 'u'))
{ {
/* missing second-half of surrogate. */ /* missing second-half of surrogate. */
*ep = str; *ep = str;
return 0; return NULL;
} }
uc2 = parse_hex4(ptr + 3); uc2 = parse_hex4(ptr + 3);
ptr += 6; /* \uXXXX */ ptr += 6; /* \uXXXX */
@ -577,7 +577,7 @@ static const char *parse_string(cJSON *item, const char *str, const char **ep)
{ {
/* invalid second-half of surrogate. */ /* invalid second-half of surrogate. */
*ep = str; *ep = str;
return 0; return NULL;
} }
/* calculate unicode codepoint from the surrogate pair */ /* calculate unicode codepoint from the surrogate pair */
uc = 0x10000 + (((uc & 0x3FF) << 10) | (uc2 & 0x3FF)); uc = 0x10000 + (((uc & 0x3FF) << 10) | (uc2 & 0x3FF));
@ -626,7 +626,7 @@ static const char *parse_string(cJSON *item, const char *str, const char **ep)
break; break;
default: default:
*ep = str; *ep = str;
return 0; return NULL;
} }
ptr++; ptr++;
} }
@ -663,7 +663,7 @@ static char *print_string_ptr(const char *str, printbuffer *p)
} }
if (!out) if (!out)
{ {
return 0; return NULL;
} }
strcpy(out, "\"\""); strcpy(out, "\"\"");
@ -693,7 +693,7 @@ static char *print_string_ptr(const char *str, printbuffer *p)
} }
if (!out) if (!out)
{ {
return 0; return NULL;
} }
ptr2 = out; ptr2 = out;
@ -730,7 +730,7 @@ static char *print_string_ptr(const char *str, printbuffer *p)
} }
if (!out) if (!out)
{ {
return 0; return NULL;
} }
ptr2 = out; ptr2 = out;
@ -813,14 +813,14 @@ static const char *skip(const char *in)
/* Parse an object - create a new root, and populate. */ /* Parse an object - create a new root, and populate. */
cJSON *cJSON_ParseWithOpts(const char *value, const char **return_parse_end, int require_null_terminated) cJSON *cJSON_ParseWithOpts(const char *value, const char **return_parse_end, int require_null_terminated)
{ {
const char *end = 0; const char *end = NULL;
/* use global error pointer if no specific one was given */ /* use global error pointer if no specific one was given */
const char **ep = return_parse_end ? return_parse_end : &global_ep; const char **ep = return_parse_end ? return_parse_end : &global_ep;
cJSON *c = cJSON_New_Item(); cJSON *c = cJSON_New_Item();
*ep = 0; *ep = NULL;
if (!c) /* memory fail */ if (!c) /* memory fail */
{ {
return 0; return NULL;
} }
end = parse_value(c, skip(value), ep); end = parse_value(c, skip(value), ep);
@ -828,7 +828,7 @@ cJSON *cJSON_ParseWithOpts(const char *value, const char **return_parse_end, int
{ {
/* parse failure. ep is set. */ /* parse failure. ep is set. */
cJSON_Delete(c); cJSON_Delete(c);
return 0; return NULL;
} }
/* if we require null-terminated JSON without appended garbage, skip and then check for a null terminator */ /* if we require null-terminated JSON without appended garbage, skip and then check for a null terminator */
@ -839,7 +839,7 @@ cJSON *cJSON_ParseWithOpts(const char *value, const char **return_parse_end, int
{ {
cJSON_Delete(c); cJSON_Delete(c);
*ep = end; *ep = end;
return 0; return NULL;
} }
} }
if (return_parse_end) if (return_parse_end)
@ -873,7 +873,7 @@ char *cJSON_PrintBuffered(const cJSON *item, int prebuffer, int fmt)
p.buffer = (char*)cJSON_malloc(prebuffer); p.buffer = (char*)cJSON_malloc(prebuffer);
if (!p.buffer) if (!p.buffer)
{ {
return 0; return NULL;
} }
p.length = prebuffer; p.length = prebuffer;
p.offset = 0; p.offset = 0;
@ -888,7 +888,7 @@ static const char *parse_value(cJSON *item, const char *value, const char **ep)
if (!value) if (!value)
{ {
/* Fail on null. */ /* Fail on null. */
return 0; return NULL;
} }
/* parse the different types of values */ /* parse the different types of values */
@ -927,17 +927,17 @@ static const char *parse_value(cJSON *item, const char *value, const char **ep)
/* failure. */ /* failure. */
*ep = value; *ep = value;
return 0; return NULL;
} }
/* Render a value to text. */ /* Render a value to text. */
static char *print_value(const cJSON *item, int depth, int fmt, printbuffer *p) static char *print_value(const cJSON *item, int depth, int fmt, printbuffer *p)
{ {
char *out = 0; char *out = NULL;
if (!item) if (!item)
{ {
return 0; return NULL;
} }
if (p) if (p)
{ {
@ -1017,7 +1017,7 @@ static const char *parse_array(cJSON *item,const char *value,const char **ep)
{ {
/* not an array! */ /* not an array! */
*ep = value; *ep = value;
return 0; return NULL;
} }
item->type = cJSON_Array; item->type = cJSON_Array;
@ -1032,13 +1032,13 @@ static const char *parse_array(cJSON *item,const char *value,const char **ep)
if (!item->child) if (!item->child)
{ {
/* memory fail */ /* memory fail */
return 0; return NULL;
} }
/* skip any spacing, get the value. */ /* skip any spacing, get the value. */
value = skip(parse_value(child, skip(value), ep)); value = skip(parse_value(child, skip(value), ep));
if (!value) if (!value)
{ {
return 0; return NULL;
} }
/* loop through the comma separated array elements */ /* loop through the comma separated array elements */
@ -1048,7 +1048,7 @@ static const char *parse_array(cJSON *item,const char *value,const char **ep)
if (!(new_item = cJSON_New_Item())) if (!(new_item = cJSON_New_Item()))
{ {
/* memory fail */ /* memory fail */
return 0; return NULL;
} }
/* add new item to end of the linked list */ /* add new item to end of the linked list */
child->next = new_item; child->next = new_item;
@ -1060,7 +1060,7 @@ static const char *parse_array(cJSON *item,const char *value,const char **ep)
if (!value) if (!value)
{ {
/* memory fail */ /* memory fail */
return 0; return NULL;
} }
} }
@ -1073,14 +1073,14 @@ static const char *parse_array(cJSON *item,const char *value,const char **ep)
/* malformed. */ /* malformed. */
*ep = value; *ep = value;
return 0; return NULL;
} }
/* Render an array to text */ /* Render an array to text */
static char *print_array(const cJSON *item, int depth, int fmt, printbuffer *p) static char *print_array(const cJSON *item, int depth, int fmt, printbuffer *p)
{ {
char **entries; char **entries;
char *out = 0; char *out = NULL;
char *ptr; char *ptr;
char *ret; char *ret;
int len = 5; int len = 5;
@ -1124,7 +1124,7 @@ static char *print_array(const cJSON *item, int depth, int fmt, printbuffer *p)
ptr = ensure(p, 1); ptr = ensure(p, 1);
if (!ptr) if (!ptr)
{ {
return 0; return NULL;
} }
*ptr = '['; *ptr = '[';
p->offset++; p->offset++;
@ -1140,14 +1140,14 @@ static char *print_array(const cJSON *item, int depth, int fmt, printbuffer *p)
ptr = ensure(p, len + 1); ptr = ensure(p, len + 1);
if (!ptr) if (!ptr)
{ {
return 0; return NULL;
} }
*ptr++ = ','; *ptr++ = ',';
if(fmt) if(fmt)
{ {
*ptr++ = ' '; *ptr++ = ' ';
} }
*ptr = 0; *ptr = '\0';
p->offset += len; p->offset += len;
} }
child = child->next; child = child->next;
@ -1155,7 +1155,7 @@ static char *print_array(const cJSON *item, int depth, int fmt, printbuffer *p)
ptr = ensure(p, 2); ptr = ensure(p, 2);
if (!ptr) if (!ptr)
{ {
return 0; return NULL;
} }
*ptr++ = ']'; *ptr++ = ']';
*ptr = '\0'; *ptr = '\0';
@ -1167,9 +1167,9 @@ static char *print_array(const cJSON *item, int depth, int fmt, printbuffer *p)
entries = (char**)cJSON_malloc(numentries * sizeof(char*)); entries = (char**)cJSON_malloc(numentries * sizeof(char*));
if (!entries) if (!entries)
{ {
return 0; return NULL;
} }
memset(entries, 0, numentries * sizeof(char*)); memset(entries, '\0', numentries * sizeof(char*));
/* Retrieve all the results: */ /* Retrieve all the results: */
child = item->child; child = item->child;
@ -1211,7 +1211,7 @@ static char *print_array(const cJSON *item, int depth, int fmt, printbuffer *p)
} }
} }
cJSON_free(entries); cJSON_free(entries);
return 0; return NULL;
} }
/* Compose the output array. */ /* Compose the output array. */
@ -1230,7 +1230,7 @@ static char *print_array(const cJSON *item, int depth, int fmt, printbuffer *p)
{ {
*ptr++ = ' '; *ptr++ = ' ';
} }
*ptr = 0; *ptr = '\0';
} }
cJSON_free(entries[i]); cJSON_free(entries[i]);
} }
@ -1250,7 +1250,7 @@ static const char *parse_object(cJSON *item, const char *value, const char **ep)
{ {
/* not an object! */ /* not an object! */
*ep = value; *ep = value;
return 0; return NULL;
} }
item->type = cJSON_Object; item->type = cJSON_Object;
@ -1265,29 +1265,29 @@ static const char *parse_object(cJSON *item, const char *value, const char **ep)
item->child = child; item->child = child;
if (!item->child) if (!item->child)
{ {
return 0; return NULL;
} }
/* parse first key */ /* parse first key */
value = skip(parse_string(child, skip(value), ep)); value = skip(parse_string(child, skip(value), ep));
if (!value) if (!value)
{ {
return 0; return NULL;
} }
/* use string as key, not value */ /* use string as key, not value */
child->string = child->valuestring; child->string = child->valuestring;
child->valuestring = 0; child->valuestring = NULL;
if (*value != ':') if (*value != ':')
{ {
/* invalid object. */ /* invalid object. */
*ep = value; *ep = value;
return 0; return NULL;
} }
/* skip any spacing, get the value. */ /* skip any spacing, get the value. */
value = skip(parse_value(child, skip(value + 1), ep)); value = skip(parse_value(child, skip(value + 1), ep));
if (!value) if (!value)
{ {
return 0; return NULL;
} }
while (*value == ',') while (*value == ',')
@ -1296,7 +1296,7 @@ static const char *parse_object(cJSON *item, const char *value, const char **ep)
if (!(new_item = cJSON_New_Item())) if (!(new_item = cJSON_New_Item()))
{ {
/* memory fail */ /* memory fail */
return 0; return NULL;
} }
/* add to linked list */ /* add to linked list */
child->next = new_item; child->next = new_item;
@ -1306,24 +1306,24 @@ static const char *parse_object(cJSON *item, const char *value, const char **ep)
value = skip(parse_string(child, skip(value + 1), ep)); value = skip(parse_string(child, skip(value + 1), ep));
if (!value) if (!value)
{ {
return 0; return NULL;
} }
/* use string as key, not value */ /* use string as key, not value */
child->string = child->valuestring; child->string = child->valuestring;
child->valuestring = 0; child->valuestring = NULL;
if (*value != ':') if (*value != ':')
{ {
/* invalid object. */ /* invalid object. */
*ep = value; *ep = value;
return 0; return NULL;
} }
/* skip any spacing, get the value. */ /* skip any spacing, get the value. */
value = skip(parse_value(child, skip(value + 1), ep)); value = skip(parse_value(child, skip(value + 1), ep));
if (!value) if (!value)
{ {
return 0; return NULL;
} }
} }
/* end of object */ /* end of object */
@ -1334,15 +1334,15 @@ static const char *parse_object(cJSON *item, const char *value, const char **ep)
/* malformed */ /* malformed */
*ep = value; *ep = value;
return 0; return NULL;
} }
/* Render an object to text. */ /* Render an object to text. */
static char *print_object(const cJSON *item, int depth, int fmt, printbuffer *p) static char *print_object(const cJSON *item, int depth, int fmt, printbuffer *p)
{ {
char **entries = 0; char **entries = NULL;
char **names = 0; char **names = NULL;
char *out = 0; char *out = NULL;
char *ptr; char *ptr;
char *ret; char *ret;
char *str; char *str;
@ -1374,7 +1374,7 @@ static char *print_object(const cJSON *item, int depth, int fmt, printbuffer *p)
} }
if (!out) if (!out)
{ {
return 0; return NULL;
} }
ptr = out; ptr = out;
*ptr++ = '{'; *ptr++ = '{';
@ -1399,7 +1399,7 @@ static char *print_object(const cJSON *item, int depth, int fmt, printbuffer *p)
ptr = ensure(p, len + 1); ptr = ensure(p, len + 1);
if (!ptr) if (!ptr)
{ {
return 0; return NULL;
} }
*ptr++ = '{'; *ptr++ = '{';
@ -1419,7 +1419,7 @@ static char *print_object(const cJSON *item, int depth, int fmt, printbuffer *p)
ptr = ensure(p, depth); ptr = ensure(p, depth);
if (!ptr) if (!ptr)
{ {
return 0; return NULL;
} }
for (j = 0; j < depth; j++) for (j = 0; j < depth; j++)
{ {
@ -1436,7 +1436,7 @@ static char *print_object(const cJSON *item, int depth, int fmt, printbuffer *p)
ptr = ensure(p, len); ptr = ensure(p, len);
if (!ptr) if (!ptr)
{ {
return 0; return NULL;
} }
*ptr++ = ':'; *ptr++ = ':';
if (fmt) if (fmt)
@ -1454,7 +1454,7 @@ static char *print_object(const cJSON *item, int depth, int fmt, printbuffer *p)
ptr = ensure(p, len + 1); ptr = ensure(p, len + 1);
if (!ptr) if (!ptr)
{ {
return 0; return NULL;
} }
if (child->next) if (child->next)
{ {
@ -1474,7 +1474,7 @@ static char *print_object(const cJSON *item, int depth, int fmt, printbuffer *p)
ptr = ensure(p, fmt ? (depth + 1) : 2); ptr = ensure(p, fmt ? (depth + 1) : 2);
if (!ptr) if (!ptr)
{ {
return 0; return NULL;
} }
if (fmt) if (fmt)
{ {
@ -1493,16 +1493,16 @@ static char *print_object(const cJSON *item, int depth, int fmt, printbuffer *p)
entries = (char**)cJSON_malloc(numentries * sizeof(char*)); entries = (char**)cJSON_malloc(numentries * sizeof(char*));
if (!entries) if (!entries)
{ {
return 0; return NULL;
} }
names = (char**)cJSON_malloc(numentries * sizeof(char*)); names = (char**)cJSON_malloc(numentries * sizeof(char*));
if (!names) if (!names)
{ {
cJSON_free(entries); cJSON_free(entries);
return 0; return NULL;
} }
memset(entries,0, sizeof(char*) * numentries); memset(entries, '\0', sizeof(char*) * numentries);
memset(names, 0, sizeof(char*) * numentries); memset(names, '\0', sizeof(char*) * numentries);
/* Collect all the results into our arrays: */ /* Collect all the results into our arrays: */
child = item->child; child = item->child;
@ -1553,7 +1553,7 @@ static char *print_object(const cJSON *item, int depth, int fmt, printbuffer *p)
} }
cJSON_free(names); cJSON_free(names);
cJSON_free(entries); cJSON_free(entries);
return 0; return NULL;
} }
/* Compose the output: */ /* Compose the output: */
@ -1563,7 +1563,7 @@ static char *print_object(const cJSON *item, int depth, int fmt, printbuffer *p)
{ {
*ptr++ = '\n'; *ptr++ = '\n';
} }
*ptr = 0; *ptr = '\0';
for (i = 0; i < numentries; i++) for (i = 0; i < numentries; i++)
{ {
if (fmt) if (fmt)
@ -1591,7 +1591,7 @@ static char *print_object(const cJSON *item, int depth, int fmt, printbuffer *p)
{ {
*ptr++ = '\n'; *ptr++ = '\n';
} }
*ptr = 0; *ptr = '\0';
cJSON_free(names[i]); cJSON_free(names[i]);
cJSON_free(entries[i]); cJSON_free(entries[i]);
} }
@ -1627,7 +1627,7 @@ int cJSON_GetArraySize(const cJSON *array)
cJSON *cJSON_GetArrayItem(const cJSON *array, int item) cJSON *cJSON_GetArrayItem(const cJSON *array, int item)
{ {
cJSON *c = array ? array->child : 0; cJSON *c = array ? array->child : NULL;
while (c && item > 0) while (c && item > 0)
{ {
item--; item--;
@ -1639,7 +1639,7 @@ cJSON *cJSON_GetArrayItem(const cJSON *array, int item)
cJSON *cJSON_GetObjectItem(const cJSON *object, const char *string) cJSON *cJSON_GetObjectItem(const cJSON *object, const char *string)
{ {
cJSON *c = object ? object->child : 0; cJSON *c = object ? object->child : NULL;
while (c && cJSON_strcasecmp(c->string, string)) while (c && cJSON_strcasecmp(c->string, string))
{ {
c = c->next; c = c->next;
@ -1665,12 +1665,12 @@ static cJSON *create_reference(const cJSON *item)
cJSON *ref = cJSON_New_Item(); cJSON *ref = cJSON_New_Item();
if (!ref) if (!ref)
{ {
return 0; return NULL;
} }
memcpy(ref, item, sizeof(cJSON)); memcpy(ref, item, sizeof(cJSON));
ref->string = 0; ref->string = NULL;
ref->type |= cJSON_IsReference; ref->type |= cJSON_IsReference;
ref->next = ref->prev = 0; ref->next = ref->prev = NULL;
return ref; return ref;
} }
@ -1752,7 +1752,7 @@ cJSON *cJSON_DetachItemFromArray(cJSON *array, int which)
if (!c) if (!c)
{ {
/* item doesn't exist */ /* item doesn't exist */
return 0; return NULL;
} }
if (c->prev) if (c->prev)
{ {
@ -1768,7 +1768,7 @@ cJSON *cJSON_DetachItemFromArray(cJSON *array, int which)
array->child = c->next; array->child = c->next;
} }
/* make sure the detached item doesn't point anywhere anymore */ /* make sure the detached item doesn't point anywhere anymore */
c->prev = c->next = 0; c->prev = c->next = NULL;
return c; return c;
} }
@ -1792,7 +1792,7 @@ cJSON *cJSON_DetachItemFromObject(cJSON *object, const char *string)
return cJSON_DetachItemFromArray(object, i); return cJSON_DetachItemFromArray(object, i);
} }
return 0; return NULL;
} }
void cJSON_DeleteItemFromObject(cJSON *object, const char *string) void cJSON_DeleteItemFromObject(cJSON *object, const char *string)
@ -1853,7 +1853,7 @@ void cJSON_ReplaceItemInArray(cJSON *array, int which, cJSON *newitem)
{ {
newitem->prev->next = newitem; newitem->prev->next = newitem;
} }
c->next = c->prev = 0; c->next = c->prev = NULL;
cJSON_Delete(c); cJSON_Delete(c);
} }
@ -1947,7 +1947,7 @@ cJSON *cJSON_CreateString(const char *string)
if(!item->valuestring) if(!item->valuestring)
{ {
cJSON_Delete(item); cJSON_Delete(item);
return 0; return NULL;
} }
} }
@ -1980,8 +1980,8 @@ cJSON *cJSON_CreateObject(void)
cJSON *cJSON_CreateIntArray(const int *numbers, int count) cJSON *cJSON_CreateIntArray(const int *numbers, int count)
{ {
int i; int i;
cJSON *n = 0; cJSON *n = NULL;
cJSON *p = 0; cJSON *p = NULL;
cJSON *a = cJSON_CreateArray(); cJSON *a = cJSON_CreateArray();
for(i = 0; a && (i < count); i++) for(i = 0; a && (i < count); i++)
{ {
@ -1989,7 +1989,7 @@ cJSON *cJSON_CreateIntArray(const int *numbers, int count)
if (!n) if (!n)
{ {
cJSON_Delete(a); cJSON_Delete(a);
return 0; return NULL;
} }
if(!i) if(!i)
{ {
@ -2008,8 +2008,8 @@ cJSON *cJSON_CreateIntArray(const int *numbers, int count)
cJSON *cJSON_CreateFloatArray(const float *numbers, int count) cJSON *cJSON_CreateFloatArray(const float *numbers, int count)
{ {
int i; int i;
cJSON *n = 0; cJSON *n = NULL;
cJSON *p = 0; cJSON *p = NULL;
cJSON *a = cJSON_CreateArray(); cJSON *a = cJSON_CreateArray();
for(i = 0; a && (i < count); i++) for(i = 0; a && (i < count); i++)
{ {
@ -2017,7 +2017,7 @@ cJSON *cJSON_CreateFloatArray(const float *numbers, int count)
if(!n) if(!n)
{ {
cJSON_Delete(a); cJSON_Delete(a);
return 0; return NULL;
} }
if(!i) if(!i)
{ {
@ -2036,8 +2036,8 @@ cJSON *cJSON_CreateFloatArray(const float *numbers, int count)
cJSON *cJSON_CreateDoubleArray(const double *numbers, int count) cJSON *cJSON_CreateDoubleArray(const double *numbers, int count)
{ {
int i; int i;
cJSON *n = 0; cJSON *n = NULL;
cJSON *p = 0; cJSON *p = NULL;
cJSON *a = cJSON_CreateArray(); cJSON *a = cJSON_CreateArray();
for(i = 0;a && (i < count); i++) for(i = 0;a && (i < count); i++)
{ {
@ -2045,7 +2045,7 @@ cJSON *cJSON_CreateDoubleArray(const double *numbers, int count)
if(!n) if(!n)
{ {
cJSON_Delete(a); cJSON_Delete(a);
return 0; return NULL;
} }
if(!i) if(!i)
{ {
@ -2064,8 +2064,8 @@ cJSON *cJSON_CreateDoubleArray(const double *numbers, int count)
cJSON *cJSON_CreateStringArray(const char **strings, int count) cJSON *cJSON_CreateStringArray(const char **strings, int count)
{ {
int i; int i;
cJSON *n = 0; cJSON *n = NULL;
cJSON *p = 0; cJSON *p = NULL;
cJSON *a = cJSON_CreateArray(); cJSON *a = cJSON_CreateArray();
for (i = 0; a && (i < count); i++) for (i = 0; a && (i < count); i++)
{ {
@ -2073,7 +2073,7 @@ cJSON *cJSON_CreateStringArray(const char **strings, int count)
if(!n) if(!n)
{ {
cJSON_Delete(a); cJSON_Delete(a);
return 0; return NULL;
} }
if(!i) if(!i)
{ {
@ -2094,19 +2094,19 @@ cJSON *cJSON_Duplicate(const cJSON *item, int recurse)
{ {
cJSON *newitem; cJSON *newitem;
cJSON *cptr; cJSON *cptr;
cJSON *nptr = 0; cJSON *nptr = NULL;
cJSON *newchild; cJSON *newchild;
/* Bail on bad ptr */ /* Bail on bad ptr */
if (!item) if (!item)
{ {
return 0; return NULL;
} }
/* Create new item */ /* Create new item */
newitem = cJSON_New_Item(); newitem = cJSON_New_Item();
if (!newitem) if (!newitem)
{ {
return 0; return NULL;
} }
/* Copy over all vars */ /* Copy over all vars */
newitem->type = item->type & (~cJSON_IsReference); newitem->type = item->type & (~cJSON_IsReference);
@ -2118,7 +2118,7 @@ cJSON *cJSON_Duplicate(const cJSON *item, int recurse)
if (!newitem->valuestring) if (!newitem->valuestring)
{ {
cJSON_Delete(newitem); cJSON_Delete(newitem);
return 0; return NULL;
} }
} }
if (item->string) if (item->string)
@ -2127,7 +2127,7 @@ cJSON *cJSON_Duplicate(const cJSON *item, int recurse)
if (!newitem->string) if (!newitem->string)
{ {
cJSON_Delete(newitem); cJSON_Delete(newitem);
return 0; return NULL;
} }
} }
/* If non-recursive, then we're done! */ /* If non-recursive, then we're done! */
@ -2143,7 +2143,7 @@ cJSON *cJSON_Duplicate(const cJSON *item, int recurse)
if (!newchild) if (!newchild)
{ {
cJSON_Delete(newitem); cJSON_Delete(newitem);
return 0; return NULL;
} }
if (nptr) if (nptr)
{ {

View File

@ -12,7 +12,7 @@ static char* cJSONUtils_strdup(const char* str)
len = strlen(str) + 1; len = strlen(str) + 1;
if (!(copy = (char*)malloc(len))) if (!(copy = (char*)malloc(len)))
{ {
return 0; return NULL;
} }
memcpy(copy, str, len); memcpy(copy, str, len);
@ -153,12 +153,12 @@ char *cJSONUtils_FindPointerFromObjectTo(cJSON *object, cJSON *target)
/* reached leaf of the tree, found nothing */ /* reached leaf of the tree, found nothing */
free(found); free(found);
return 0; return NULL;
} }
} }
/* not found */ /* not found */
return 0; return NULL;
} }
cJSON *cJSONUtils_GetPointer(cJSON *object, const char *pointer) cJSON *cJSONUtils_GetPointer(cJSON *object, const char *pointer)
@ -177,7 +177,7 @@ cJSON *cJSONUtils_GetPointer(cJSON *object, const char *pointer)
if (*pointer && (*pointer != '/')) if (*pointer && (*pointer != '/'))
{ {
/* not end of string or new path token */ /* not end of string or new path token */
return 0; return NULL;
} }
object = cJSON_GetArrayItem(object, which); object = cJSON_GetArrayItem(object, which);
} }
@ -197,7 +197,7 @@ cJSON *cJSONUtils_GetPointer(cJSON *object, const char *pointer)
} }
else else
{ {
return 0; return NULL;
} }
} }
@ -222,10 +222,10 @@ static void cJSONUtils_InplaceDecodePointerString(char *string)
static cJSON *cJSONUtils_PatchDetach(cJSON *object, const char *path) static cJSON *cJSONUtils_PatchDetach(cJSON *object, const char *path)
{ {
char *parentptr = 0; char *parentptr = NULL;
char *childptr = 0; char *childptr = NULL;
cJSON *parent = 0; cJSON *parent = NULL;
cJSON *ret = 0; cJSON *ret = NULL;
/* copy path and split it in parent and child */ /* copy path and split it in parent and child */
parentptr = cJSONUtils_strdup(path); parentptr = cJSONUtils_strdup(path);
@ -241,7 +241,7 @@ static cJSON *cJSONUtils_PatchDetach(cJSON *object, const char *path)
if (!parent) if (!parent)
{ {
/* Couldn't find object to remove child from. */ /* Couldn't find object to remove child from. */
ret = 0; ret = NULL;
} }
else if ((parent->type & 0xFF) == cJSON_Array) else if ((parent->type & 0xFF) == cJSON_Array)
{ {
@ -317,13 +317,13 @@ static int cJSONUtils_Compare(cJSON *a, cJSON *b)
static int cJSONUtils_ApplyPatch(cJSON *object, cJSON *patch) static int cJSONUtils_ApplyPatch(cJSON *object, cJSON *patch)
{ {
cJSON *op = 0; cJSON *op = NULL;
cJSON *path = 0; cJSON *path = NULL;
cJSON *value = 0; cJSON *value = NULL;
cJSON *parent = 0; cJSON *parent = NULL;
int opcode = 0; int opcode = 0;
char *parentptr = 0; char *parentptr = NULL;
char *childptr = 0; char *childptr = NULL;
op = cJSON_GetObjectItem(patch, "op"); op = cJSON_GetObjectItem(patch, "op");
path = cJSON_GetObjectItem(patch, "path"); path = cJSON_GetObjectItem(patch, "path");
@ -666,13 +666,13 @@ static cJSON *cJSONUtils_SortList(cJSON *list)
if (second && second->prev) if (second && second->prev)
{ {
/* Split the lists */ /* Split the lists */
second->prev->next = 0; second->prev->next = NULL;
} }
/* Recursively sort the sub-lists. */ /* Recursively sort the sub-lists. */
first = cJSONUtils_SortList(first); first = cJSONUtils_SortList(first);
second = cJSONUtils_SortList(second); second = cJSONUtils_SortList(second);
list = ptr = 0; list = ptr = NULL;
while (first && second) /* Merge the sub-lists */ while (first && second) /* Merge the sub-lists */
{ {
@ -773,7 +773,7 @@ cJSON* cJSONUtils_MergePatch(cJSON *target, cJSON *patch)
cJSON *cJSONUtils_GenerateMergePatch(cJSON *from, cJSON *to) cJSON *cJSONUtils_GenerateMergePatch(cJSON *from, cJSON *to)
{ {
cJSON *patch = 0; cJSON *patch = NULL;
if (!to) if (!to)
{ {
/* patch to delete everything */ /* patch to delete everything */
@ -821,7 +821,7 @@ cJSON *cJSONUtils_GenerateMergePatch(cJSON *from, cJSON *to)
if (!patch->child) if (!patch->child)
{ {
cJSON_Delete(patch); cJSON_Delete(patch);
return 0; return NULL;
} }
return patch; return patch;