|
@@ -51,11 +51,11 @@ typedef int cjbool;
|
|
|
#define true ((cjbool)1)
|
|
|
#define false ((cjbool)0)
|
|
|
|
|
|
-static const char *global_ep = NULL;
|
|
|
+static const unsigned char *global_ep = NULL;
|
|
|
|
|
|
const char *cJSON_GetErrorPtr(void)
|
|
|
{
|
|
|
- return global_ep;
|
|
|
+ return (const char*) global_ep;
|
|
|
}
|
|
|
|
|
|
extern const char* cJSON_Version(void)
|
|
@@ -67,7 +67,7 @@ extern const char* cJSON_Version(void)
|
|
|
}
|
|
|
|
|
|
/* case insensitive strcmp */
|
|
|
-static int cJSON_strcasecmp(const char *s1, const char *s2)
|
|
|
+static int cJSON_strcasecmp(const unsigned char *s1, const unsigned char *s2)
|
|
|
{
|
|
|
if (!s1)
|
|
|
{
|
|
@@ -77,7 +77,7 @@ static int cJSON_strcasecmp(const char *s1, const char *s2)
|
|
|
{
|
|
|
return 1;
|
|
|
}
|
|
|
- for(; tolower(*(const unsigned char *)s1) == tolower(*(const unsigned char *)s2); ++s1, ++s2)
|
|
|
+ for(; tolower(*s1) == tolower(*s2); ++s1, ++s2)
|
|
|
{
|
|
|
if (*s1 == '\0')
|
|
|
{
|
|
@@ -85,24 +85,24 @@ static int cJSON_strcasecmp(const char *s1, const char *s2)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- return tolower(*(const unsigned char *)s1) - tolower(*(const unsigned char *)s2);
|
|
|
+ return tolower(*s1) - tolower(*s2);
|
|
|
}
|
|
|
|
|
|
static void *(*cJSON_malloc)(size_t sz) = malloc;
|
|
|
static void (*cJSON_free)(void *ptr) = free;
|
|
|
|
|
|
-static char* cJSON_strdup(const char* str)
|
|
|
+static unsigned char* cJSON_strdup(const unsigned char* str)
|
|
|
{
|
|
|
size_t len = 0;
|
|
|
- char *copy = NULL;
|
|
|
+ unsigned char *copy = NULL;
|
|
|
|
|
|
if (str == NULL)
|
|
|
{
|
|
|
return NULL;
|
|
|
}
|
|
|
|
|
|
- len = strlen(str) + 1;
|
|
|
- if (!(copy = (char*)cJSON_malloc(len)))
|
|
|
+ len = strlen((const char*)str) + 1;
|
|
|
+ if (!(copy = (unsigned char*)cJSON_malloc(len)))
|
|
|
{
|
|
|
return NULL;
|
|
|
}
|
|
@@ -162,7 +162,7 @@ void cJSON_Delete(cJSON *c)
|
|
|
}
|
|
|
|
|
|
/* Parse the input text to generate a number, and populate the result into item. */
|
|
|
-static const char *parse_number(cJSON *item, const char *num)
|
|
|
+static const unsigned char *parse_number(cJSON *item, const unsigned char *num)
|
|
|
{
|
|
|
double n = 0;
|
|
|
double sign = 1;
|
|
@@ -254,16 +254,16 @@ static int pow2gt (int x)
|
|
|
|
|
|
typedef struct
|
|
|
{
|
|
|
- char *buffer;
|
|
|
+ unsigned char *buffer;
|
|
|
int length;
|
|
|
int offset;
|
|
|
cjbool noalloc;
|
|
|
} printbuffer;
|
|
|
|
|
|
/* realloc printbuffer if necessary to have at least "needed" bytes more */
|
|
|
-static char* ensure(printbuffer *p, int needed)
|
|
|
+static unsigned char* ensure(printbuffer *p, int needed)
|
|
|
{
|
|
|
- char *newbuffer = NULL;
|
|
|
+ unsigned char *newbuffer = NULL;
|
|
|
int newsize = 0;
|
|
|
if (!p || !p->buffer)
|
|
|
{
|
|
@@ -280,7 +280,7 @@ static char* ensure(printbuffer *p, int needed)
|
|
|
}
|
|
|
|
|
|
newsize = pow2gt(needed);
|
|
|
- newbuffer = (char*)cJSON_malloc(newsize);
|
|
|
+ newbuffer = (unsigned char*)cJSON_malloc(newsize);
|
|
|
if (!newbuffer)
|
|
|
{
|
|
|
cJSON_free(p->buffer);
|
|
@@ -303,20 +303,20 @@ static char* ensure(printbuffer *p, int needed)
|
|
|
/* calculate the new length of the string in a printbuffer */
|
|
|
static int update(const printbuffer *p)
|
|
|
{
|
|
|
- char *str = NULL;
|
|
|
+ unsigned char *str = NULL;
|
|
|
if (!p || !p->buffer)
|
|
|
{
|
|
|
return 0;
|
|
|
}
|
|
|
str = p->buffer + p->offset;
|
|
|
|
|
|
- return p->offset + strlen(str);
|
|
|
+ return p->offset + strlen((char*)str);
|
|
|
}
|
|
|
|
|
|
/* Render the number nicely from the given item into a string. */
|
|
|
-static char *print_number(const cJSON *item, printbuffer *p)
|
|
|
+static unsigned char *print_number(const cJSON *item, printbuffer *p)
|
|
|
{
|
|
|
- char *str = NULL;
|
|
|
+ unsigned char *str = NULL;
|
|
|
double d = item->valuedouble;
|
|
|
/* special case for 0. */
|
|
|
if (d == 0)
|
|
@@ -327,11 +327,11 @@ static char *print_number(const cJSON *item, printbuffer *p)
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- str = (char*)cJSON_malloc(2);
|
|
|
+ str = (unsigned char*)cJSON_malloc(2);
|
|
|
}
|
|
|
if (str)
|
|
|
{
|
|
|
- strcpy(str,"0");
|
|
|
+ strcpy((char*)str,"0");
|
|
|
}
|
|
|
}
|
|
|
/* value is an int */
|
|
@@ -344,11 +344,11 @@ static char *print_number(const cJSON *item, printbuffer *p)
|
|
|
else
|
|
|
{
|
|
|
/* 2^64+1 can be represented in 21 chars. */
|
|
|
- str = (char*)cJSON_malloc(21);
|
|
|
+ str = (unsigned char*)cJSON_malloc(21);
|
|
|
}
|
|
|
if (str)
|
|
|
{
|
|
|
- sprintf(str, "%d", item->valueint);
|
|
|
+ sprintf((char*)str, "%d", item->valueint);
|
|
|
}
|
|
|
}
|
|
|
/* value is a floating point number */
|
|
@@ -362,26 +362,26 @@ static char *print_number(const cJSON *item, printbuffer *p)
|
|
|
else
|
|
|
{
|
|
|
/* This is a nice tradeoff. */
|
|
|
- str=(char*)cJSON_malloc(64);
|
|
|
+ str = (unsigned char*)cJSON_malloc(64);
|
|
|
}
|
|
|
if (str)
|
|
|
{
|
|
|
/* This checks for NaN and Infinity */
|
|
|
if ((d * 0) != 0)
|
|
|
{
|
|
|
- sprintf(str, "null");
|
|
|
+ sprintf((char*)str, "null");
|
|
|
}
|
|
|
else if ((fabs(floor(d) - d) <= DBL_EPSILON) && (fabs(d) < 1.0e60))
|
|
|
{
|
|
|
- sprintf(str, "%.0f", d);
|
|
|
+ sprintf((char*)str, "%.0f", d);
|
|
|
}
|
|
|
else if ((fabs(d) < 1.0e-6) || (fabs(d) > 1.0e9))
|
|
|
{
|
|
|
- sprintf(str, "%e", d);
|
|
|
+ sprintf((char*)str, "%e", d);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- sprintf(str, "%f", d);
|
|
|
+ sprintf((char*)str, "%f", d);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -389,7 +389,7 @@ static char *print_number(const cJSON *item, printbuffer *p)
|
|
|
}
|
|
|
|
|
|
/* parse 4 digit hexadecimal number */
|
|
|
-static unsigned parse_hex4(const char *str)
|
|
|
+static unsigned parse_hex4(const unsigned char *str)
|
|
|
{
|
|
|
unsigned h = 0;
|
|
|
/* first digit */
|
|
@@ -487,12 +487,12 @@ static const unsigned char firstByteMark[7] =
|
|
|
};
|
|
|
|
|
|
/* Parse the input text into an unescaped cstring, and populate item. */
|
|
|
-static const char *parse_string(cJSON *item, const char *str, const char **ep)
|
|
|
+static const unsigned char *parse_string(cJSON *item, const unsigned char *str, const unsigned char **ep)
|
|
|
{
|
|
|
- const char *ptr = str + 1;
|
|
|
- const char *end_ptr =str + 1;
|
|
|
- char *ptr2 = NULL;
|
|
|
- char *out = NULL;
|
|
|
+ const unsigned char *ptr = str + 1;
|
|
|
+ const unsigned char *end_ptr =str + 1;
|
|
|
+ unsigned char *ptr2 = NULL;
|
|
|
+ unsigned char *out = NULL;
|
|
|
int len = 0;
|
|
|
unsigned uc = 0;
|
|
|
unsigned uc2 = 0;
|
|
@@ -520,12 +520,12 @@ static const char *parse_string(cJSON *item, const char *str, const char **ep)
|
|
|
}
|
|
|
|
|
|
/* This is at most how long we need for the string, roughly. */
|
|
|
- out = (char*)cJSON_malloc(len + 1);
|
|
|
+ out = (unsigned char*)cJSON_malloc(len + 1);
|
|
|
if (!out)
|
|
|
{
|
|
|
return NULL;
|
|
|
}
|
|
|
- item->valuestring = out; /* assign here so out will be deleted during cJSON_Delete() later */
|
|
|
+ item->valuestring = (char*)out; /* assign here so out will be deleted during cJSON_Delete() later */
|
|
|
item->type = cJSON_String;
|
|
|
|
|
|
ptr = str + 1;
|
|
@@ -668,11 +668,11 @@ static const char *parse_string(cJSON *item, const char *str, const char **ep)
|
|
|
}
|
|
|
|
|
|
/* Render the cstring provided to an escaped version that can be printed. */
|
|
|
-static char *print_string_ptr(const char *str, printbuffer *p)
|
|
|
+static unsigned char *print_string_ptr(const unsigned char *str, printbuffer *p)
|
|
|
{
|
|
|
- const char *ptr = NULL;
|
|
|
- char *ptr2 = NULL;
|
|
|
- char *out = NULL;
|
|
|
+ const unsigned char *ptr = NULL;
|
|
|
+ unsigned char *ptr2 = NULL;
|
|
|
+ unsigned char *out = NULL;
|
|
|
int len = 0;
|
|
|
cjbool flag = false;
|
|
|
unsigned char token = '\0';
|
|
@@ -686,13 +686,13 @@ static char *print_string_ptr(const char *str, printbuffer *p)
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- out = (char*)cJSON_malloc(3);
|
|
|
+ out = (unsigned char*)cJSON_malloc(3);
|
|
|
}
|
|
|
if (!out)
|
|
|
{
|
|
|
return NULL;
|
|
|
}
|
|
|
- strcpy(out, "\"\"");
|
|
|
+ strcpy((char*)out, "\"\"");
|
|
|
|
|
|
return out;
|
|
|
}
|
|
@@ -716,7 +716,7 @@ static char *print_string_ptr(const char *str, printbuffer *p)
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- out = (char*)cJSON_malloc(len + 3);
|
|
|
+ out = (unsigned char*)cJSON_malloc(len + 3);
|
|
|
}
|
|
|
if (!out)
|
|
|
{
|
|
@@ -725,7 +725,7 @@ static char *print_string_ptr(const char *str, printbuffer *p)
|
|
|
|
|
|
ptr2 = out;
|
|
|
*ptr2++ = '\"';
|
|
|
- strcpy(ptr2, str);
|
|
|
+ strcpy((char*)ptr2, (const char*)str);
|
|
|
ptr2[len] = '\"';
|
|
|
ptr2[len + 1] = '\0';
|
|
|
|
|
@@ -754,7 +754,7 @@ static char *print_string_ptr(const char *str, printbuffer *p)
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- out = (char*)cJSON_malloc(len + 3);
|
|
|
+ out = (unsigned char*)cJSON_malloc(len + 3);
|
|
|
}
|
|
|
if (!out)
|
|
|
{
|
|
@@ -767,7 +767,7 @@ static char *print_string_ptr(const char *str, printbuffer *p)
|
|
|
/* copy the string */
|
|
|
while (*ptr)
|
|
|
{
|
|
|
- if (((unsigned char)*ptr > 31) && (*ptr != '\"') && (*ptr != '\\'))
|
|
|
+ if ((*ptr > 31) && (*ptr != '\"') && (*ptr != '\\'))
|
|
|
{
|
|
|
/* normal character, copy */
|
|
|
*ptr2++ = *ptr++;
|
|
@@ -801,7 +801,7 @@ static char *print_string_ptr(const char *str, printbuffer *p)
|
|
|
break;
|
|
|
default:
|
|
|
/* escape and print as unicode codepoint */
|
|
|
- sprintf(ptr2, "u%04x", token);
|
|
|
+ sprintf((char*)ptr2, "u%04x", token);
|
|
|
ptr2 += 5;
|
|
|
break;
|
|
|
}
|
|
@@ -814,23 +814,23 @@ static char *print_string_ptr(const char *str, printbuffer *p)
|
|
|
}
|
|
|
|
|
|
/* Invoke print_string_ptr (which is useful) on an item. */
|
|
|
-static char *print_string(const cJSON *item, printbuffer *p)
|
|
|
+static unsigned char *print_string(const cJSON *item, printbuffer *p)
|
|
|
{
|
|
|
- return print_string_ptr(item->valuestring, p);
|
|
|
+ return print_string_ptr((unsigned char*)item->valuestring, p);
|
|
|
}
|
|
|
|
|
|
/* Predeclare these prototypes. */
|
|
|
-static const char *parse_value(cJSON *item, const char *value, const char **ep);
|
|
|
-static char *print_value(const cJSON *item, int depth, cjbool fmt, printbuffer *p);
|
|
|
-static const char *parse_array(cJSON *item, const char *value, const char **ep);
|
|
|
-static char *print_array(const cJSON *item, int depth, cjbool fmt, printbuffer *p);
|
|
|
-static const char *parse_object(cJSON *item, const char *value, const char **ep);
|
|
|
-static char *print_object(const cJSON *item, int depth, cjbool fmt, printbuffer *p);
|
|
|
+static const unsigned char *parse_value(cJSON *item, const unsigned char *value, const unsigned char **ep);
|
|
|
+static unsigned char *print_value(const cJSON *item, int depth, cjbool fmt, printbuffer *p);
|
|
|
+static const unsigned char *parse_array(cJSON *item, const unsigned char *value, const unsigned char **ep);
|
|
|
+static unsigned char *print_array(const cJSON *item, int depth, cjbool fmt, printbuffer *p);
|
|
|
+static const unsigned char *parse_object(cJSON *item, const unsigned char *value, const unsigned char **ep);
|
|
|
+static unsigned char *print_object(const cJSON *item, int depth, cjbool fmt, printbuffer *p);
|
|
|
|
|
|
/* Utility to jump whitespace and cr/lf */
|
|
|
-static const char *skip(const char *in)
|
|
|
+static const unsigned char *skip(const unsigned char *in)
|
|
|
{
|
|
|
- while (in && *in && ((unsigned char)*in<=32))
|
|
|
+ while (in && *in && (*in <= 32))
|
|
|
{
|
|
|
in++;
|
|
|
}
|
|
@@ -841,9 +841,9 @@ static const char *skip(const char *in)
|
|
|
/* Parse an object - create a new root, and populate. */
|
|
|
cJSON *cJSON_ParseWithOpts(const char *value, const char **return_parse_end, cjbool require_null_terminated)
|
|
|
{
|
|
|
- const char *end = NULL;
|
|
|
+ const unsigned char *end = NULL;
|
|
|
/* use global error pointer if no specific one was given */
|
|
|
- const char **ep = return_parse_end ? return_parse_end : &global_ep;
|
|
|
+ const unsigned char **ep = return_parse_end ? (const unsigned char**)return_parse_end : &global_ep;
|
|
|
cJSON *c = cJSON_New_Item();
|
|
|
*ep = NULL;
|
|
|
if (!c) /* memory fail */
|
|
@@ -851,7 +851,7 @@ cJSON *cJSON_ParseWithOpts(const char *value, const char **return_parse_end, cjb
|
|
|
return NULL;
|
|
|
}
|
|
|
|
|
|
- end = parse_value(c, skip(value), ep);
|
|
|
+ end = parse_value(c, skip((const unsigned char*)value), ep);
|
|
|
if (!end)
|
|
|
{
|
|
|
/* parse failure. ep is set. */
|
|
@@ -872,7 +872,7 @@ cJSON *cJSON_ParseWithOpts(const char *value, const char **return_parse_end, cjb
|
|
|
}
|
|
|
if (return_parse_end)
|
|
|
{
|
|
|
- *return_parse_end = end;
|
|
|
+ *return_parse_end = (const char*)end;
|
|
|
}
|
|
|
|
|
|
return c;
|
|
@@ -887,18 +887,18 @@ cJSON *cJSON_Parse(const char *value)
|
|
|
/* Render a cJSON item/entity/structure to text. */
|
|
|
char *cJSON_Print(const cJSON *item)
|
|
|
{
|
|
|
- return print_value(item, 0, 1, 0);
|
|
|
+ return (char*)print_value(item, 0, 1, 0);
|
|
|
}
|
|
|
|
|
|
char *cJSON_PrintUnformatted(const cJSON *item)
|
|
|
{
|
|
|
- return print_value(item, 0, 0, 0);
|
|
|
+ return (char*)print_value(item, 0, 0, 0);
|
|
|
}
|
|
|
|
|
|
char *cJSON_PrintBuffered(const cJSON *item, int prebuffer, cjbool fmt)
|
|
|
{
|
|
|
printbuffer p;
|
|
|
- p.buffer = (char*)cJSON_malloc(prebuffer);
|
|
|
+ p.buffer = (unsigned char*)cJSON_malloc(prebuffer);
|
|
|
if (!p.buffer)
|
|
|
{
|
|
|
return NULL;
|
|
@@ -907,13 +907,13 @@ char *cJSON_PrintBuffered(const cJSON *item, int prebuffer, cjbool fmt)
|
|
|
p.offset = 0;
|
|
|
p.noalloc = false;
|
|
|
|
|
|
- return print_value(item, 0, fmt, &p);
|
|
|
+ return (char*)print_value(item, 0, fmt, &p);
|
|
|
}
|
|
|
|
|
|
-int cJSON_PrintPreallocated(cJSON *item,char *buf, const int len, const cjbool fmt)
|
|
|
+int cJSON_PrintPreallocated(cJSON *item, char *buf, const int len, const cjbool fmt)
|
|
|
{
|
|
|
printbuffer p;
|
|
|
- p.buffer = buf;
|
|
|
+ p.buffer = (unsigned char*)buf;
|
|
|
p.length = len;
|
|
|
p.offset = 0;
|
|
|
p.noalloc = true;
|
|
@@ -921,7 +921,7 @@ int cJSON_PrintPreallocated(cJSON *item,char *buf, const int len, const cjbool f
|
|
|
}
|
|
|
|
|
|
/* Parser core - when encountering text, process appropriately. */
|
|
|
-static const char *parse_value(cJSON *item, const char *value, const char **ep)
|
|
|
+static const unsigned char *parse_value(cJSON *item, const unsigned char *value, const unsigned char **ep)
|
|
|
{
|
|
|
if (!value)
|
|
|
{
|
|
@@ -930,17 +930,17 @@ static const char *parse_value(cJSON *item, const char *value, const char **ep)
|
|
|
}
|
|
|
|
|
|
/* parse the different types of values */
|
|
|
- if (!strncmp(value, "null", 4))
|
|
|
+ if (!strncmp((const char*)value, "null", 4))
|
|
|
{
|
|
|
item->type = cJSON_NULL;
|
|
|
return value + 4;
|
|
|
}
|
|
|
- if (!strncmp(value, "false", 5))
|
|
|
+ if (!strncmp((const char*)value, "false", 5))
|
|
|
{
|
|
|
item->type = cJSON_False;
|
|
|
return value + 5;
|
|
|
}
|
|
|
- if (!strncmp(value, "true", 4))
|
|
|
+ if (!strncmp((const char*)value, "true", 4))
|
|
|
{
|
|
|
item->type = cJSON_True;
|
|
|
item->valueint = 1;
|
|
@@ -969,9 +969,9 @@ static const char *parse_value(cJSON *item, const char *value, const char **ep)
|
|
|
}
|
|
|
|
|
|
/* Render a value to text. */
|
|
|
-static char *print_value(const cJSON *item, int depth, cjbool fmt, printbuffer *p)
|
|
|
+static unsigned char *print_value(const cJSON *item, int depth, cjbool fmt, printbuffer *p)
|
|
|
{
|
|
|
- char *out = NULL;
|
|
|
+ unsigned char *out = NULL;
|
|
|
|
|
|
if (!item)
|
|
|
{
|
|
@@ -985,21 +985,21 @@ static char *print_value(const cJSON *item, int depth, cjbool fmt, printbuffer *
|
|
|
out = ensure(p, 5);
|
|
|
if (out)
|
|
|
{
|
|
|
- strcpy(out, "null");
|
|
|
+ strcpy((char*)out, "null");
|
|
|
}
|
|
|
break;
|
|
|
case cJSON_False:
|
|
|
out = ensure(p, 6);
|
|
|
if (out)
|
|
|
{
|
|
|
- strcpy(out, "false");
|
|
|
+ strcpy((char*)out, "false");
|
|
|
}
|
|
|
break;
|
|
|
case cJSON_True:
|
|
|
out = ensure(p, 5);
|
|
|
if (out)
|
|
|
{
|
|
|
- strcpy(out, "true");
|
|
|
+ strcpy((char*)out, "true");
|
|
|
}
|
|
|
break;
|
|
|
case cJSON_Number:
|
|
@@ -1045,19 +1045,19 @@ static char *print_value(const cJSON *item, int depth, cjbool fmt, printbuffer *
|
|
|
switch ((item->type) & 0xFF)
|
|
|
{
|
|
|
case cJSON_NULL:
|
|
|
- out = cJSON_strdup("null");
|
|
|
+ out = cJSON_strdup((const unsigned char*)"null");
|
|
|
break;
|
|
|
case cJSON_False:
|
|
|
- out = cJSON_strdup("false");
|
|
|
+ out = cJSON_strdup((const unsigned char*)"false");
|
|
|
break;
|
|
|
case cJSON_True:
|
|
|
- out = cJSON_strdup("true");
|
|
|
+ out = cJSON_strdup((const unsigned char*)"true");
|
|
|
break;
|
|
|
case cJSON_Number:
|
|
|
out = print_number(item, 0);
|
|
|
break;
|
|
|
case cJSON_Raw:
|
|
|
- out = cJSON_strdup(item->valuestring);
|
|
|
+ out = cJSON_strdup((unsigned char*)item->valuestring);
|
|
|
break;
|
|
|
case cJSON_String:
|
|
|
out = print_string(item, 0);
|
|
@@ -1078,7 +1078,7 @@ static char *print_value(const cJSON *item, int depth, cjbool fmt, printbuffer *
|
|
|
}
|
|
|
|
|
|
/* Build an array from input text. */
|
|
|
-static const char *parse_array(cJSON *item,const char *value,const char **ep)
|
|
|
+static const unsigned char *parse_array(cJSON *item, const unsigned char *value, const unsigned char **ep)
|
|
|
{
|
|
|
cJSON *child = NULL;
|
|
|
if (*value != '[')
|
|
@@ -1145,12 +1145,12 @@ static const char *parse_array(cJSON *item,const char *value,const char **ep)
|
|
|
}
|
|
|
|
|
|
/* Render an array to text */
|
|
|
-static char *print_array(const cJSON *item, int depth, cjbool fmt, printbuffer *p)
|
|
|
+static unsigned char *print_array(const cJSON *item, int depth, cjbool fmt, printbuffer *p)
|
|
|
{
|
|
|
- char **entries;
|
|
|
- char *out = NULL;
|
|
|
- char *ptr = NULL;
|
|
|
- char *ret = NULL;
|
|
|
+ unsigned char **entries;
|
|
|
+ unsigned char *out = NULL;
|
|
|
+ unsigned char *ptr = NULL;
|
|
|
+ unsigned char *ret = NULL;
|
|
|
int len = 5;
|
|
|
cJSON *child = item->child;
|
|
|
int numentries = 0;
|
|
@@ -1174,11 +1174,11 @@ static char *print_array(const cJSON *item, int depth, cjbool fmt, printbuffer *
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- out = (char*)cJSON_malloc(3);
|
|
|
+ out = (unsigned char*)cJSON_malloc(3);
|
|
|
}
|
|
|
if (out)
|
|
|
{
|
|
|
- strcpy(out,"[]");
|
|
|
+ strcpy((char*)out, "[]");
|
|
|
}
|
|
|
|
|
|
return out;
|
|
@@ -1235,12 +1235,12 @@ static char *print_array(const cJSON *item, int depth, cjbool fmt, printbuffer *
|
|
|
else
|
|
|
{
|
|
|
/* Allocate an array to hold the pointers to all printed values */
|
|
|
- entries = (char**)cJSON_malloc(numentries * sizeof(char*));
|
|
|
+ entries = (unsigned char**)cJSON_malloc(numentries * sizeof(unsigned char*));
|
|
|
if (!entries)
|
|
|
{
|
|
|
return NULL;
|
|
|
}
|
|
|
- memset(entries, '\0', numentries * sizeof(char*));
|
|
|
+ memset(entries, '\0', numentries * sizeof(unsigned char*));
|
|
|
|
|
|
/* Retrieve all the results: */
|
|
|
child = item->child;
|
|
@@ -1250,7 +1250,7 @@ static char *print_array(const cJSON *item, int depth, cjbool fmt, printbuffer *
|
|
|
entries[i++] = ret;
|
|
|
if (ret)
|
|
|
{
|
|
|
- len += strlen(ret) + 2 + (fmt ? 1 : 0);
|
|
|
+ len += strlen((char*)ret) + 2 + (fmt ? 1 : 0);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
@@ -1262,7 +1262,7 @@ static char *print_array(const cJSON *item, int depth, cjbool fmt, printbuffer *
|
|
|
/* If we didn't fail, try to malloc the output string */
|
|
|
if (!fail)
|
|
|
{
|
|
|
- out = (char*)cJSON_malloc(len);
|
|
|
+ out = (unsigned char*)cJSON_malloc(len);
|
|
|
}
|
|
|
/* If that fails, we fail. */
|
|
|
if (!out)
|
|
@@ -1291,7 +1291,7 @@ static char *print_array(const cJSON *item, int depth, cjbool fmt, printbuffer *
|
|
|
*ptr = '\0';
|
|
|
for (i = 0; i < numentries; i++)
|
|
|
{
|
|
|
- tmplen = strlen(entries[i]);
|
|
|
+ tmplen = strlen((char*)entries[i]);
|
|
|
memcpy(ptr, entries[i], tmplen);
|
|
|
ptr += tmplen;
|
|
|
if (i != (numentries - 1))
|
|
@@ -1314,7 +1314,7 @@ static char *print_array(const cJSON *item, int depth, cjbool fmt, printbuffer *
|
|
|
}
|
|
|
|
|
|
/* Build an object from the text. */
|
|
|
-static const char *parse_object(cJSON *item, const char *value, const char **ep)
|
|
|
+static const unsigned char *parse_object(cJSON *item, const unsigned char *value, const unsigned char **ep)
|
|
|
{
|
|
|
cJSON *child = NULL;
|
|
|
if (*value != '{')
|
|
@@ -1409,14 +1409,14 @@ static const char *parse_object(cJSON *item, const char *value, const char **ep)
|
|
|
}
|
|
|
|
|
|
/* Render an object to text. */
|
|
|
-static char *print_object(const cJSON *item, int depth, cjbool fmt, printbuffer *p)
|
|
|
-{
|
|
|
- char **entries = NULL;
|
|
|
- char **names = NULL;
|
|
|
- char *out = NULL;
|
|
|
- char *ptr = NULL;
|
|
|
- char *ret = NULL;
|
|
|
- char *str = NULL;
|
|
|
+static unsigned char *print_object(const cJSON *item, int depth, cjbool fmt, printbuffer *p)
|
|
|
+{
|
|
|
+ unsigned char **entries = NULL;
|
|
|
+ unsigned char **names = NULL;
|
|
|
+ unsigned char *out = NULL;
|
|
|
+ unsigned char *ptr = NULL;
|
|
|
+ unsigned char *ret = NULL;
|
|
|
+ unsigned char *str = NULL;
|
|
|
int len = 7;
|
|
|
int i = 0;
|
|
|
int j = 0;
|
|
@@ -1441,7 +1441,7 @@ static char *print_object(const cJSON *item, int depth, cjbool fmt, printbuffer
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- out = (char*)cJSON_malloc(fmt ? depth + 4 : 3);
|
|
|
+ out = (unsigned char*)cJSON_malloc(fmt ? depth + 4 : 3);
|
|
|
}
|
|
|
if (!out)
|
|
|
{
|
|
@@ -1500,7 +1500,7 @@ static char *print_object(const cJSON *item, int depth, cjbool fmt, printbuffer
|
|
|
}
|
|
|
|
|
|
/* print key */
|
|
|
- if (!print_string_ptr(child->string, p))
|
|
|
+ if (!print_string_ptr((unsigned char*)child->string, p))
|
|
|
{
|
|
|
return NULL;
|
|
|
}
|
|
@@ -1567,19 +1567,19 @@ static char *print_object(const cJSON *item, int depth, cjbool fmt, printbuffer
|
|
|
else
|
|
|
{
|
|
|
/* Allocate space for the names and the objects */
|
|
|
- entries = (char**)cJSON_malloc(numentries * sizeof(char*));
|
|
|
+ entries = (unsigned char**)cJSON_malloc(numentries * sizeof(unsigned char*));
|
|
|
if (!entries)
|
|
|
{
|
|
|
return NULL;
|
|
|
}
|
|
|
- names = (char**)cJSON_malloc(numentries * sizeof(char*));
|
|
|
+ names = (unsigned char**)cJSON_malloc(numentries * sizeof(unsigned char*));
|
|
|
if (!names)
|
|
|
{
|
|
|
cJSON_free(entries);
|
|
|
return NULL;
|
|
|
}
|
|
|
- memset(entries, '\0', sizeof(char*) * numentries);
|
|
|
- memset(names, '\0', sizeof(char*) * numentries);
|
|
|
+ memset(entries, '\0', sizeof(unsigned char*) * numentries);
|
|
|
+ memset(names, '\0', sizeof(unsigned char*) * numentries);
|
|
|
|
|
|
/* Collect all the results into our arrays: */
|
|
|
child = item->child;
|
|
@@ -1590,11 +1590,11 @@ static char *print_object(const cJSON *item, int depth, cjbool fmt, printbuffer
|
|
|
}
|
|
|
while (child && !fail)
|
|
|
{
|
|
|
- names[i] = str = print_string_ptr(child->string, 0); /* print key */
|
|
|
+ names[i] = str = print_string_ptr((unsigned char*)child->string, 0); /* print key */
|
|
|
entries[i++] = ret = print_value(child, depth, fmt, 0);
|
|
|
if (str && ret)
|
|
|
{
|
|
|
- len += strlen(ret) + strlen(str) + 2 + (fmt ? 2 + depth : 0);
|
|
|
+ len += strlen((char*)ret) + strlen((char*)str) + 2 + (fmt ? 2 + depth : 0);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
@@ -1606,7 +1606,7 @@ static char *print_object(const cJSON *item, int depth, cjbool fmt, printbuffer
|
|
|
/* Try to allocate the output string */
|
|
|
if (!fail)
|
|
|
{
|
|
|
- out = (char*)cJSON_malloc(len);
|
|
|
+ out = (unsigned char*)cJSON_malloc(len);
|
|
|
}
|
|
|
if (!out)
|
|
|
{
|
|
@@ -1650,7 +1650,7 @@ static char *print_object(const cJSON *item, int depth, cjbool fmt, printbuffer
|
|
|
*ptr++='\t';
|
|
|
}
|
|
|
}
|
|
|
- tmplen = strlen(names[i]);
|
|
|
+ tmplen = strlen((char*)names[i]);
|
|
|
memcpy(ptr, names[i], tmplen);
|
|
|
ptr += tmplen;
|
|
|
*ptr++ = ':';
|
|
@@ -1658,8 +1658,8 @@ static char *print_object(const cJSON *item, int depth, cjbool fmt, printbuffer
|
|
|
{
|
|
|
*ptr++ = '\t';
|
|
|
}
|
|
|
- strcpy(ptr, entries[i]);
|
|
|
- ptr += strlen(entries[i]);
|
|
|
+ strcpy((char*)ptr, (char*)entries[i]);
|
|
|
+ ptr += strlen((char*)entries[i]);
|
|
|
if (i != (numentries - 1))
|
|
|
{
|
|
|
*ptr++ = ',';
|
|
@@ -1717,14 +1717,14 @@ cJSON *cJSON_GetArrayItem(const cJSON *array, int item)
|
|
|
cJSON *cJSON_GetObjectItem(const cJSON *object, const char *string)
|
|
|
{
|
|
|
cJSON *c = object ? object->child : NULL;
|
|
|
- while (c && cJSON_strcasecmp(c->string, string))
|
|
|
+ while (c && cJSON_strcasecmp((unsigned char*)c->string, (const unsigned char*)string))
|
|
|
{
|
|
|
c = c->next;
|
|
|
}
|
|
|
return c;
|
|
|
}
|
|
|
|
|
|
-cjbool cJSON_HasObjectItem(const cJSON *object,const char *string)
|
|
|
+cjbool cJSON_HasObjectItem(const cJSON *object, const char *string)
|
|
|
{
|
|
|
return cJSON_GetObjectItem(object, string) ? 1 : 0;
|
|
|
}
|
|
@@ -1787,7 +1787,7 @@ void cJSON_AddItemToObject(cJSON *object, const char *string, cJSON *item)
|
|
|
{
|
|
|
cJSON_free(item->string);
|
|
|
}
|
|
|
- item->string = cJSON_strdup(string);
|
|
|
+ item->string = (char*)cJSON_strdup((const unsigned char*)string);
|
|
|
|
|
|
cJSON_AddItemToArray(object,item);
|
|
|
}
|
|
@@ -1862,7 +1862,7 @@ cJSON *cJSON_DetachItemFromObject(cJSON *object, const char *string)
|
|
|
{
|
|
|
int i = 0;
|
|
|
cJSON *c = object->child;
|
|
|
- while (c && cJSON_strcasecmp(c->string,string))
|
|
|
+ while (c && cJSON_strcasecmp((unsigned char*)c->string, (const unsigned char*)string))
|
|
|
{
|
|
|
i++;
|
|
|
c = c->next;
|
|
@@ -1941,7 +1941,7 @@ void cJSON_ReplaceItemInObject(cJSON *object, const char *string, cJSON *newitem
|
|
|
{
|
|
|
int i = 0;
|
|
|
cJSON *c = object->child;
|
|
|
- while(c && cJSON_strcasecmp(c->string, string))
|
|
|
+ while(c && cJSON_strcasecmp((unsigned char*)c->string, (const unsigned char*)string))
|
|
|
{
|
|
|
i++;
|
|
|
c = c->next;
|
|
@@ -1954,7 +1954,7 @@ void cJSON_ReplaceItemInObject(cJSON *object, const char *string, cJSON *newitem
|
|
|
cJSON_free(newitem->string);
|
|
|
}
|
|
|
|
|
|
- newitem->string = cJSON_strdup(string);
|
|
|
+ newitem->string = (char*)cJSON_strdup((const unsigned char*)string);
|
|
|
cJSON_ReplaceItemInArray(object, i, newitem);
|
|
|
}
|
|
|
}
|
|
@@ -2023,7 +2023,7 @@ cJSON *cJSON_CreateString(const char *string)
|
|
|
if(item)
|
|
|
{
|
|
|
item->type = cJSON_String;
|
|
|
- item->valuestring = cJSON_strdup(string);
|
|
|
+ item->valuestring = (char*)cJSON_strdup((const unsigned char*)string);
|
|
|
if(!item->valuestring)
|
|
|
{
|
|
|
cJSON_Delete(item);
|
|
@@ -2040,7 +2040,7 @@ extern cJSON *cJSON_CreateRaw(const char *raw)
|
|
|
if(item)
|
|
|
{
|
|
|
item->type = cJSON_Raw;
|
|
|
- item->valuestring = cJSON_strdup(raw);
|
|
|
+ item->valuestring = (char*)cJSON_strdup((const unsigned char*)raw);
|
|
|
if(!item->valuestring)
|
|
|
{
|
|
|
cJSON_Delete(item);
|
|
@@ -2211,7 +2211,7 @@ cJSON *cJSON_Duplicate(const cJSON *item, cjbool recurse)
|
|
|
newitem->valuedouble = item->valuedouble;
|
|
|
if (item->valuestring)
|
|
|
{
|
|
|
- newitem->valuestring = cJSON_strdup(item->valuestring);
|
|
|
+ newitem->valuestring = (char*)cJSON_strdup((unsigned char*)item->valuestring);
|
|
|
if (!newitem->valuestring)
|
|
|
{
|
|
|
cJSON_Delete(newitem);
|
|
@@ -2220,7 +2220,7 @@ cJSON *cJSON_Duplicate(const cJSON *item, cjbool recurse)
|
|
|
}
|
|
|
if (item->string)
|
|
|
{
|
|
|
- newitem->string = (item->type&cJSON_StringIsConst) ? item->string : cJSON_strdup(item->string);
|
|
|
+ newitem->string = (item->type&cJSON_StringIsConst) ? item->string : (char*)cJSON_strdup((unsigned char*)item->string);
|
|
|
if (!newitem->string)
|
|
|
{
|
|
|
cJSON_Delete(newitem);
|
|
@@ -2262,7 +2262,7 @@ cJSON *cJSON_Duplicate(const cJSON *item, cjbool recurse)
|
|
|
|
|
|
void cJSON_Minify(char *json)
|
|
|
{
|
|
|
- char *into = json;
|
|
|
+ unsigned char *into = (unsigned char*)json;
|
|
|
while (*json)
|
|
|
{
|
|
|
if (*json == ' ')
|