diff options
| author | Mark Pulford <mark@kyne.com.au> | 2012-01-01 23:30:34 +1030 |
|---|---|---|
| committer | Mark Pulford <mark@kyne.com.au> | 2012-01-01 23:30:34 +1030 |
| commit | 77408a81a696472338c2f90147e41fff3e81005d (patch) | |
| tree | a4972c000f94d416df20f8786f4e75e3ded5d263 /lua_cjson.c | |
| parent | 929c814b12e3575859fa0d5a8ea9950ae2187c56 (diff) | |
| download | lua-cjson-77408a81a696472338c2f90147e41fff3e81005d.tar.gz lua-cjson-77408a81a696472338c2f90147e41fff3e81005d.tar.bz2 lua-cjson-77408a81a696472338c2f90147e41fff3e81005d.zip | |
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.
Diffstat (limited to '')
| -rw-r--r-- | lua_cjson.c | 15 |
1 files changed, 15 insertions, 0 deletions
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 @@ | |||
| 67 | #define DEFAULT_ENCODE_KEEP_BUFFER 1 | 67 | #define DEFAULT_ENCODE_KEEP_BUFFER 1 |
| 68 | #define DEFAULT_ENCODE_NUMBER_PRECISION 14 | 68 | #define DEFAULT_ENCODE_NUMBER_PRECISION 14 |
| 69 | 69 | ||
| 70 | #ifdef DISABLE_INVALID_NUMBERS | ||
| 71 | #undef DEFAULT_DECODE_REFUSE_BADNUM | ||
| 72 | #define DEFAULT_DECODE_REFUSE_BADNUM 1 | ||
| 73 | #endif | ||
| 74 | |||
| 70 | typedef enum { | 75 | typedef enum { |
| 71 | T_OBJ_BEGIN, | 76 | T_OBJ_BEGIN, |
| 72 | T_OBJ_END, | 77 | T_OBJ_END, |
| @@ -341,6 +346,16 @@ static int json_cfg_refuse_invalid_numbers(lua_State *l) | |||
| 341 | &cfg->encode_refuse_badnum, | 346 | &cfg->encode_refuse_badnum, |
| 342 | &cfg->decode_refuse_badnum); | 347 | &cfg->decode_refuse_badnum); |
| 343 | 348 | ||
| 349 | #if DISABLE_INVALID_NUMBERS | ||
| 350 | /* Some non-POSIX platforms don't handle double <-> string translations | ||
| 351 | * for Infinity/NaN/hexadecimal properly. Throw an error if the | ||
| 352 | * user attempts to enable them. */ | ||
| 353 | if (!cfg->encode_refuse_badnum || !cfg->decode_refuse_badnum) { | ||
| 354 | cfg->encode_refuse_badnum = cfg->decode_refuse_badnum = 1; | ||
| 355 | luaL_error(l, "Infinity, NaN, and/or hexadecimal numbers are not supported."); | ||
| 356 | } | ||
| 357 | #endif | ||
| 358 | |||
| 344 | return 1; | 359 | return 1; |
| 345 | } | 360 | } |
| 346 | 361 | ||
