Change JSON integer's underlying type from int to long
[jansson.git] / src / load.c
index 4d08139..f86d2b5 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"
@@ -53,7 +52,7 @@ typedef struct {
     int line, column;
     union {
         char *string;
-        int integer;
+        long integer;
         double real;
     } value;
 } lex_t;
@@ -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;
@@ -438,17 +438,17 @@ static int lex_scan_number(lex_t *lex, char c, json_error_t *error)
         value = strtol(saved_text, &end, 10);
         assert(end == saved_text + lex->saved_text.length);
 
-        if((value == LONG_MAX && errno == ERANGE) || value > INT_MAX) {
+        if(value == LONG_MAX && errno == ERANGE) {
             error_set(error, lex, "too big integer");
             goto out;
         }
-        else if((value == LONG_MIN && errno == ERANGE) || value < INT_MIN) {
+        else if(value == LONG_MIN && errno == ERANGE) {
             error_set(error, lex, "too big negative integer");
             goto out;
         }
 
         lex->token = TOKEN_INTEGER;
-        lex->value.integer = (int)value;
+        lex->value.integer = value;
         return 0;
     }
 
@@ -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;
     }