From: Michael Clark Date: Tue, 13 Mar 2007 08:26:25 +0000 (+0000) Subject: * Fix bug in escaping of control characters X-Git-Tag: json-c-0.10-20120530~102 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=837240f75f359934054ccc065c7426aeb002d472;p=json-c * Fix bug in escaping of control characters Johan Bj�rklund, johbjo09 at kth dot se * Remove include "config.h" from headers (should only be included from .c files) Michael Clark git-svn-id: http://svn.metaparadigm.com/svn/json-c/trunk@12 327403b1-1117-474d-bef2-5cb71233fd97 --- diff --git a/ChangeLog b/ChangeLog index 3b0d1bb..a0f848e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +0.6 + * Fix bug in escaping of control characters + Johan Björklund, johbjo09 at kth dot se + * Remove include "config.h" from headers (should only + be included from .c files) + Michael Clark + 0.5 * Make headers C++ compatible by change *this to *obj * Add ifdef C++ extern "C" to headers diff --git a/README.html b/README.html index c55600a..7b3a65e 100644 --- a/README.html +++ b/README.html @@ -8,7 +8,7 @@

JSON-C - A JSON implementation in C

-

Latest release: json-c-0.5.tar.gz

+

Latest release: json-c-0.6.tar.gz

JSON-C implements a reference counting object model that allows you to easily construct JSON objects in C, output them as JSON formatted strings and parse JSON formatted strings back into the C representation of JSON objects.

diff --git a/bits.h b/bits.h index 379793a..2c107cc 100644 --- a/bits.h +++ b/bits.h @@ -1,5 +1,5 @@ /* - * $Id: bits.h,v 1.9 2006/01/26 02:16:28 mclark Exp $ + * $Id: bits.h,v 1.10 2006/01/30 23:07:57 mclark Exp $ * * Copyright (c) 2004, 2005 Metaparadigm Pte. Ltd. * Michael Clark @@ -12,17 +12,6 @@ #ifndef _bits_h_ #define _bits_h_ -#include "config.h" - -#if STDC_HEADERS -# include -#endif /* STDC_HEADERS */ - -/* CAW: wrapped in ifndef's to make win32 compliant -** this fails to take over GCC specifics, but this -** seems to be unimportant. - */ - #ifndef min #define min(a,b) ((a) < (b) ? (a) : (b)) #endif diff --git a/debug.h b/debug.h index f825a44..1db69ef 100644 --- a/debug.h +++ b/debug.h @@ -1,5 +1,5 @@ /* - * $Id: debug.h,v 1.4 2006/01/26 02:16:28 mclark Exp $ + * $Id: debug.h,v 1.5 2006/01/30 23:07:57 mclark Exp $ * * Copyright (c) 2004, 2005 Metaparadigm Pte. Ltd. * Michael Clark @@ -12,14 +12,6 @@ #ifndef _DEBUG_H_ #define _DEBUG_H_ -#include "config.h" - -#if HAVE_STRERROR -#define errstr strerror(errno) -#else /* !HAVE_STRERROR */ -#define errstr -#endif /* HAVE_STRERROR */ - extern void mc_set_debug(int debug); extern int mc_get_debug(); diff --git a/json_object.c b/json_object.c index fecd72b..525e217 100644 --- a/json_object.c +++ b/json_object.c @@ -1,5 +1,5 @@ /* - * $Id: json_object.c,v 1.14 2006/01/26 02:16:28 mclark Exp $ + * $Id: json_object.c,v 1.15 2006/01/30 23:07:57 mclark Exp $ * * Copyright (c) 2004, 2005 Metaparadigm Pte. Ltd. * Michael Clark @@ -23,6 +23,10 @@ #include "json_object_private.h" #include "json_tokener.h" +#if !HAVE_STRNDUP + char* strndup(const char* str, size_t n); +#endif /* !HAVE_STRNDUP */ + /* #define REFCOUNT_DEBUG 1 */ char *json_number_chars = "0123456789.+-e"; @@ -78,10 +82,12 @@ static void json_object_fini() { static int json_escape_str(struct printbuf *pb, char *str) { int pos = 0, start_offset = 0; - char c; + unsigned char c; do { c = str[pos]; switch(c) { + case '\0': + break; case '\b': case '\n': case '\r': @@ -97,14 +103,14 @@ static int json_escape_str(struct printbuf *pb, char *str) start_offset = ++pos; break; default: - if(c && c < ' ') { + if(c < ' ') { if(pos - start_offset > 0) printbuf_memappend(pb, str + start_offset, pos - start_offset); sprintbuf(pb, "\\u00%c%c", json_hex_chars[c >> 4], json_hex_chars[c & 0xf]); start_offset = ++pos; - } else if(c) pos++; + } else pos++; } } while(c); if(pos - start_offset > 0) diff --git a/json_object.h b/json_object.h index 4232447..5c25968 100644 --- a/json_object.h +++ b/json_object.h @@ -1,5 +1,5 @@ /* - * $Id: json_object.h,v 1.11 2006/01/26 02:16:28 mclark Exp $ + * $Id: json_object.h,v 1.12 2006/01/30 23:07:57 mclark Exp $ * * Copyright (c) 2004, 2005 Metaparadigm Pte. Ltd. * Michael Clark @@ -12,8 +12,6 @@ #ifndef _json_object_h_ #define _json_object_h_ -#include "config.h" - #define JSON_OBJECT_DEF_HASH_ENTIRES 16 #undef FALSE diff --git a/json_tokener.c b/json_tokener.c index 6a1ea89..a3ebf10 100644 --- a/json_tokener.c +++ b/json_tokener.c @@ -1,5 +1,5 @@ /* - * $Id: json_tokener.c,v 1.18 2006/01/26 02:16:28 mclark Exp $ + * $Id: json_tokener.c,v 1.19 2006/01/30 23:07:57 mclark Exp $ * * Copyright (c) 2004, 2005 Metaparadigm Pte. Ltd. * Michael Clark @@ -23,6 +23,14 @@ #include "json_object.h" #include "json_tokener.h" +#if !HAVE_STRNCASECMP && defined(_MSC_VER) + /* MSC has the version as _strnicmp */ +# define strncasecmp _strnicmp +#elif !HAVE_STRNCASECMP +# error You do not have strncasecmp on your system. +#endif /* HAVE_STRNCASECMP */ + + static struct json_object* json_tokener_do_parse(struct json_tokener *this); struct json_object* json_tokener_parse(char * s) diff --git a/json_tokener.h b/json_tokener.h index f36c058..12227a9 100644 --- a/json_tokener.h +++ b/json_tokener.h @@ -1,5 +1,5 @@ /* - * $Id: json_tokener.h,v 1.8 2006/01/26 02:16:28 mclark Exp $ + * $Id: json_tokener.h,v 1.9 2006/01/30 23:07:57 mclark Exp $ * * Copyright (c) 2004, 2005 Metaparadigm Pte. Ltd. * Michael Clark @@ -12,7 +12,6 @@ #ifndef _json_tokener_h_ #define _json_tokener_h_ -#include "config.h" #include "json_object.h" enum json_tokener_error { @@ -59,17 +58,6 @@ struct json_tokener struct printbuf *pb; }; -#if !HAVE_STRNCASECMP && defined(_MSC_VER) - /* MSC has the version as _strnicmp */ -# define strncasecmp _strnicmp -#elif !HAVE_STRNCASECMP -# error You do not have strncasecmp on your system. -#endif /* HAVE_STRNCASECMP */ - -#if !HAVE_STRNDUP - char* strndup(const char* str, size_t n); -#endif /* !HAVE_STRNDUP */ - extern struct json_object* json_tokener_parse(char *s); #endif diff --git a/json_util.c b/json_util.c index 0aaf0f7..e20be24 100644 --- a/json_util.c +++ b/json_util.c @@ -1,5 +1,5 @@ /* - * $Id: json_util.c,v 1.3 2006/01/26 02:16:28 mclark Exp $ + * $Id: json_util.c,v 1.4 2006/01/30 23:07:57 mclark Exp $ * * Copyright (c) 2004, 2005 Metaparadigm Pte. Ltd. * Michael Clark @@ -39,6 +39,11 @@ # include #endif /* defined(WIN32) */ +#if !HAVE_OPEN && defined(WIN32) +# define open _open +#endif + + #include "bits.h" #include "debug.h" #include "printbuf.h" diff --git a/json_util.h b/json_util.h index cbaab5d..30fe2ab 100644 --- a/json_util.h +++ b/json_util.h @@ -1,5 +1,5 @@ /* - * $Id: json_util.h,v 1.3 2006/01/26 02:16:28 mclark Exp $ + * $Id: json_util.h,v 1.4 2006/01/30 23:07:57 mclark Exp $ * * Copyright (c) 2004, 2005 Metaparadigm Pte. Ltd. * Michael Clark @@ -12,20 +12,8 @@ #ifndef _json_util_h_ #define _json_util_h_ -#include "config.h" - -#ifdef WIN32 -# define WIN32_LEAN_AND_MEAN -# include -# include -#endif - #include "json_object.h" -#if !HAVE_OPEN && defined(WIN32) -# define open _open -#endif - #define JSON_FILE_BUF_SIZE 4096 /* utlitiy functions */ diff --git a/linkhash.h b/linkhash.h index 86110b8..5c9fa85 100644 --- a/linkhash.h +++ b/linkhash.h @@ -1,5 +1,5 @@ /* - * $Id: linkhash.h,v 1.5 2006/01/26 02:16:28 mclark Exp $ + * $Id: linkhash.h,v 1.6 2006/01/30 23:07:57 mclark Exp $ * * Copyright (c) 2004, 2005 Metaparadigm Pte. Ltd. * Michael Clark @@ -12,8 +12,6 @@ #ifndef _linkhash_h_ #define _linkhash_h_ -#include "config.h" - /** * golden prime used in hash functions */