cJSON

mirror of Dave's cJSON
git clone git://git.thc420.xyz/cJSON
Log | Files | Refs | README | LICENSE

commit e95313adad341f7333b210a6845af1e2fdc77a37
parent d4906be4f004e57e10c913046e517264dadfb245
Author: Kevin Branigan <kbranigan@gmail.com>
Date:   Sun, 25 Oct 2015 23:48:38 -0400

Merge pull request #24 from FSMaxB/fix_code_order

Fix printing of empty string pointers

Diffstat:
McJSON.c | 17+++++++++--------
1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/cJSON.c b/cJSON.c @@ -253,6 +253,15 @@ static const char *parse_string(cJSON *item,const char *str) static char *print_string_ptr(const char *str,printbuffer *p) { const char *ptr;char *ptr2,*out;int len=0,flag=0;unsigned char token; + + if (!str) + { + if (p) out=ensure(p,3); + else out=(char*)cJSON_malloc(3); + if (!out) return 0; + strcpy(out,"\"\""); + return out; + } for (ptr=str;*ptr;ptr++) flag|=((*ptr>0 && *ptr<32)||(*ptr=='\"')||(*ptr=='\\'))?1:0; if (!flag) @@ -268,14 +277,6 @@ static char *print_string_ptr(const char *str,printbuffer *p) return out; } - if (!str) - { - if (p) out=ensure(p,3); - else out=(char*)cJSON_malloc(3); - if (!out) return 0; - strcpy(out,"\"\""); - return out; - } ptr=str;while ((token=*ptr) && ++len) {if (strchr("\"\\\b\f\n\r\t",token)) len++; else if (token<32) len+=5;ptr++;} if (p) out=ensure(p,len+3);