From 77408a81a696472338c2f90147e41fff3e81005d Mon Sep 17 00:00:00 2001 From: Mark Pulford Date: Sun, 1 Jan 2012 23:30:34 +1030 Subject: Add build option to disable invalid numbers Windows MinGW doesn't convert Infinity/NaN/hexadecimal numbers. Add DISABLE_INVALID_NUMBERS build option option to disable invalid numbers. --- lua_cjson.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'lua_cjson.c') diff --git a/lua_cjson.c b/lua_cjson.c index 175433a..ca85156 100644 --- a/lua_cjson.c +++ b/lua_cjson.c @@ -67,6 +67,11 @@ #define DEFAULT_ENCODE_KEEP_BUFFER 1 #define DEFAULT_ENCODE_NUMBER_PRECISION 14 +#ifdef DISABLE_INVALID_NUMBERS +#undef DEFAULT_DECODE_REFUSE_BADNUM +#define DEFAULT_DECODE_REFUSE_BADNUM 1 +#endif + typedef enum { T_OBJ_BEGIN, T_OBJ_END, @@ -341,6 +346,16 @@ static int json_cfg_refuse_invalid_numbers(lua_State *l) &cfg->encode_refuse_badnum, &cfg->decode_refuse_badnum); +#if DISABLE_INVALID_NUMBERS + /* Some non-POSIX platforms don't handle double <-> string translations + * for Infinity/NaN/hexadecimal properly. Throw an error if the + * user attempts to enable them. */ + if (!cfg->encode_refuse_badnum || !cfg->decode_refuse_badnum) { + cfg->encode_refuse_badnum = cfg->decode_refuse_badnum = 1; + luaL_error(l, "Infinity, NaN, and/or hexadecimal numbers are not supported."); + } +#endif + return 1; } -- cgit v1.2.3-55-g6feb