Merge pull request #95 from rouault/extern_json_object_set_serializer
Add extern to json_object_set_serializer so that it gets exported (Windows fix)
diff --git a/json_object.c b/json_object.c
index e12c440..b63faa4 100644
--- a/json_object.c
+++ b/json_object.c
@@ -575,10 +575,11 @@
how to handle these cases as strings */
if(isnan(jso->o.c_double))
size = snprintf(buf, 128, "NaN");
- else if(isinf(jso->o.c_double) == 1)
- size = snprintf(buf, 128, "Infinity");
- else if(isinf(jso->o.c_double) == -1)
- size = snprintf(buf, 128, "-Infinity");
+ else if(isinf(jso->o.c_double))
+ if(jso->o.c_double > 0)
+ size = snprintf(buf, 128, "Infinity");
+ else
+ size = snprintf(buf, 128, "-Infinity");
else
size = snprintf(buf, 128, "%f", jso->o.c_double);
diff --git a/json_tokener.c b/json_tokener.c
index a6924a1..8019d70 100644
--- a/json_tokener.c
+++ b/json_tokener.c
@@ -74,7 +74,7 @@
const char *json_tokener_error_desc(enum json_tokener_error jerr)
{
int jerr_int = (int)jerr;
- if (jerr_int < 0 || jerr_int > (int)sizeof(json_tokener_errors))
+ if (jerr_int < 0 || jerr_int > (int)(sizeof(json_tokener_errors) / sizeof(json_tokener_errors[0])))
return "Unknown error, invalid json_tokener_error value passed to json_tokener_error_desc()";
return json_tokener_errors[jerr];
}
@@ -265,7 +265,7 @@
if ((!ADVANCE_CHAR(str, tok)) || (!PEEK_CHAR(c, tok)))
goto out;
}
- if(c == '/') {
+ if(c == '/' && !(tok->flags & JSON_TOKENER_STRICT)) {
printbuf_reset(tok->pb);
printbuf_memappend_fast(tok->pb, &c, 1);
state = json_tokener_state_comment_start;
@@ -293,8 +293,13 @@
printbuf_reset(tok->pb);
tok->st_pos = 0;
goto redo_char;
- case '"':
case '\'':
+ if (tok->flags & JSON_TOKENER_STRICT) {
+ /* in STRICT mode only double-quote are allowed */
+ tok->err = json_tokener_error_parse_unexpected;
+ goto out;
+ }
+ case '"':
state = json_tokener_state_string;
printbuf_reset(tok->pb);
tok->quote_char = c;
@@ -764,6 +769,13 @@
} /* while(POP_CHAR) */
out:
+ if (c &&
+ (state == json_tokener_state_finish) &&
+ (tok->depth == 0) &&
+ (tok->flags & JSON_TOKENER_STRICT)) {
+ /* unexpected char after JSON data */
+ tok->err = json_tokener_error_parse_unexpected;
+ }
if (!c) { /* We hit an eof char (0) */
if(state != json_tokener_state_finish &&
saved_state != json_tokener_state_finish)