aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lua_cjson.c26
-rw-r--r--manual.txt3
2 files changed, 16 insertions, 13 deletions
diff --git a/lua_cjson.c b/lua_cjson.c
index b14c242..498c686 100644
--- a/lua_cjson.c
+++ b/lua_cjson.c
@@ -321,6 +321,18 @@ static int json_cfg_encode_keep_buffer(lua_State *l)
321 return 1; 321 return 1;
322} 322}
323 323
324#if defined(DISABLE_INVALID_NUMBERS) && !defined(USE_INTERNAL_FPCONV)
325void json_verify_invalid_number_setting(lua_State *l, int *setting)
326{
327 if (*setting == 1) {
328 *setting = 0;
329 luaL_error(l, "Infinity, NaN, and/or hexadecimal numbers are not supported.");
330 }
331}
332#else
333#define json_verify_invalid_number_setting(l, s) do { } while(0)
334#endif
335
324static int json_cfg_encode_invalid_numbers(lua_State *l) 336static int json_cfg_encode_invalid_numbers(lua_State *l)
325{ 337{
326 static const char *options[] = { "off", "on", "null", NULL }; 338 static const char *options[] = { "off", "on", "null", NULL };
@@ -328,12 +340,7 @@ static int json_cfg_encode_invalid_numbers(lua_State *l)
328 340
329 json_enum_option(l, 1, &cfg->encode_invalid_numbers, options, 1); 341 json_enum_option(l, 1, &cfg->encode_invalid_numbers, options, 1);
330 342
331#if DISABLE_INVALID_NUMBERS 343 json_verify_invalid_number_setting(l, &cfg->encode_invalid_numbers);
332 if (cfg->encode_invalid_numbers == 1) {
333 cfg->encode_invalid_numbers = 0;
334 luaL_error(l, "Infinity, NaN, and/or hexadecimal numbers are not supported.");
335 }
336#endif
337 344
338 return 1; 345 return 1;
339} 346}
@@ -344,12 +351,7 @@ static int json_cfg_decode_invalid_numbers(lua_State *l)
344 351
345 json_enum_option(l, 1, &cfg->decode_invalid_numbers, NULL, 1); 352 json_enum_option(l, 1, &cfg->decode_invalid_numbers, NULL, 1);
346 353
347#if DISABLE_INVALID_NUMBERS 354 json_verify_invalid_number_setting(l, &cfg->encode_invalid_numbers);
348 if (cfg->decode_invalid_numbers) {
349 cfg->decode_invalid_numbers = 0;
350 luaL_error(l, "Infinity, NaN, and/or hexadecimal numbers are not supported.");
351 }
352#endif
353 355
354 return 1; 356 return 1;
355} 357}
diff --git a/manual.txt b/manual.txt
index eacd2c7..d7c916a 100644
--- a/manual.txt
+++ b/manual.txt
@@ -120,7 +120,8 @@ DISABLE_INVALID_NUMBERS:: Recommended on platforms where ++strtod++(3) /
120 ++sprintf++(3) are not POSIX compliant (Eg, Windows MinGW). Prevents 120 ++sprintf++(3) are not POSIX compliant (Eg, Windows MinGW). Prevents
121 +cjson.encode_invalid_numbers+ and +cjson.decode_invalid_numbers+ 121 +cjson.encode_invalid_numbers+ and +cjson.decode_invalid_numbers+
122 from being enabled. However, +cjson.encode_invalid_numbers+ may be 122 from being enabled. However, +cjson.encode_invalid_numbers+ may be
123 set to +"null"+. 123 set to +"null"+. This option is unnecessary and is ignored when
124 using built-in floating point conversion.
124 125
125 126
126Built-in dtoa() support 127Built-in dtoa() support