Zero the visited flag after an encoding error
[jansson.git] / src / load.c
index 32d6500..d49a4da 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2009 Petri Lehtinen <petri@digip.org>
+ * Copyright (c) 2009, 2010 Petri Lehtinen <petri@digip.org>
  *
  * Jansson is free software; you can redistribute it and/or modify
  * it under the terms of the MIT license. See LICENSE for details.
@@ -14,7 +14,6 @@
 #include <string.h>
 #include <stdarg.h>
 #include <assert.h>
-#include <stdint.h>
 
 #include <jansson.h>
 #include "jansson_private.h"
@@ -114,7 +113,8 @@ static void error_set(json_error_t *error, const lex_t *lex,
 
 /*** lexical analyzer ***/
 
-void stream_init(stream_t *stream, get_func get, eof_func eof, void *data)
+static void
+stream_init(stream_t *stream, get_func get, eof_func eof, void *data)
 {
     stream->get = get;
     stream->eof = eof;
@@ -149,7 +149,7 @@ static char stream_get(stream_t *stream, json_error_t *error)
             for(i = 1; i < count; i++)
                 stream->buffer[i] = stream->get(stream->data);
 
-            if(!utf8_check_full(stream->buffer, count))
+            if(!utf8_check_full(stream->buffer, count, NULL))
                 goto out;
 
             stream->stream_pos += count;
@@ -484,14 +484,7 @@ static int lex_scan_number(lex_t *lex, char c, json_error_t *error)
     value = strtod(saved_text, &end);
     assert(end == saved_text + lex->saved_text.length);
 
-    if(value == 0 && errno == ERANGE) {
-        error_set(error, lex, "real number underflow");
-        goto out;
-    }
-
-    /* Cannot test for +/-HUGE_VAL because the HUGE_VAL constant is
-       only defined in C99 mode. So let's trust in sole errno. */
-    else if(errno == ERANGE) {
+    if(errno == ERANGE && value != 0) {
         error_set(error, lex, "real number overflow");
         goto out;
     }
@@ -772,7 +765,7 @@ static json_t *parse_value(lex_t *lex, json_error_t *error)
     return json;
 }
 
-json_t *parse_json(lex_t *lex, json_error_t *error)
+static json_t *parse_json(lex_t *lex, json_error_t *error)
 {
     error_init(error);