aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorPetri Lehtinen <petri@digip.org>2014-12-18 15:16:14 +0200
committerPetri Lehtinen <petri@digip.org>2014-12-18 15:16:14 +0200
commit5508ab403d71f003bddbf849eb1f57f371b18387 (patch)
treeb771be7f00900e101da0da4daf9fe43bbb5fd618 /test
parentd799ee11b42b72f5cd1e5570d35b0a5270571e31 (diff)
downloadjansson-5508ab403d71f003bddbf849eb1f57f371b18387.zip
jansson-5508ab403d71f003bddbf849eb1f57f371b18387.tar.gz
jansson-5508ab403d71f003bddbf849eb1f57f371b18387.tar.bz2
Honor JSON_DECODE_INT_AS_REAL at lexical stage
This has the consequence that numbers are never converted to integers when JSON_DECODE_INT_AS_REAL is set, and thus it works correctly all integers that are representable as double. Fixes #212.
Diffstat (limited to 'test')
-rw-r--r--test/suites/api/test_load.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/test/suites/api/test_load.c b/test/suites/api/test_load.c
index d451853..80d159f 100644
--- a/test/suites/api/test_load.c
+++ b/test/suites/api/test_load.c
@@ -97,6 +97,8 @@ static void decode_int_as_real()
json_int_t expected;
#endif
+ char big[311];
+
json = json_loads("42", JSON_DECODE_INT_AS_REAL | JSON_DECODE_ANY, &error);
if (!json || !json_is_real(json) || json_real_value(json) != 42.0)
fail("json_load decode int as real failed - int");
@@ -113,6 +115,18 @@ static void decode_int_as_real()
fail("json_load decode int as real failed - expected imprecision");
json_decref(json);
#endif
+
+ /* 1E309 overflows. Here we create 1E309 as a decimal number, i.e.
+ 1000...(309 zeroes)...0. */
+ big[0] = '1';
+ memset(big + 1, '0', 309);
+ big[310] = '\0';
+
+ json = json_loads(big, JSON_DECODE_INT_AS_REAL | JSON_DECODE_ANY, &error);
+ if (json || strcmp(error.text, "real number overflow") != 0)
+ fail("json_load decode int as real failed - expected overflow");
+ json_decref(json);
+
}
static void allow_nul()