diff options
| author | Mark Pulford <mark@kyne.com.au> | 2011-11-29 22:47:35 +1030 |
|---|---|---|
| committer | Mark Pulford <mark@kyne.com.au> | 2011-11-29 22:47:35 +1030 |
| commit | 630bb3f16f27c72e3fc2daf3161c96f0fd9c1ba0 (patch) | |
| tree | 34265a52407f5d61ca5304a4fff2b0f9f1c5753e /lua_cjson.c | |
| parent | 83c15a39a071a5bb4bcb41385ed58cc6d8fae6de (diff) | |
| download | lua-cjson-630bb3f16f27c72e3fc2daf3161c96f0fd9c1ba0.tar.gz lua-cjson-630bb3f16f27c72e3fc2daf3161c96f0fd9c1ba0.tar.bz2 lua-cjson-630bb3f16f27c72e3fc2daf3161c96f0fd9c1ba0.zip | |
Add workaround to handle platforms that print -nan
Diffstat (limited to '')
| -rw-r--r-- | lua_cjson.c | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/lua_cjson.c b/lua_cjson.c index 1226e71..806a67c 100644 --- a/lua_cjson.c +++ b/lua_cjson.c | |||
| @@ -623,12 +623,17 @@ static void json_append_number(lua_State *l, strbuf_t *json, int index, | |||
| 623 | if (cfg->encode_refuse_badnum && (isinf(num) || isnan(num))) | 623 | if (cfg->encode_refuse_badnum && (isinf(num) || isnan(num))) |
| 624 | json_encode_exception(l, cfg, index, "must not be NaN or Inf"); | 624 | json_encode_exception(l, cfg, index, "must not be NaN or Inf"); |
| 625 | 625 | ||
| 626 | /* Lowest double printed with %.14g is 21 characters long: | 626 | if (isnan(num)) { |
| 627 | * -1.7976931348623e+308 | 627 | /* Some platforms may print -nan, just hard code it */ |
| 628 | * | 628 | strbuf_append_mem(json, "nan", 3); |
| 629 | * Use 32 to include the \0, and a few extra just in case.. | 629 | } else { |
| 630 | */ | 630 | /* Lowest double printed with %.14g is 21 characters long: |
| 631 | strbuf_append_fmt(json, 32, cfg->number_fmt, num); | 631 | * -1.7976931348623e+308 |
| 632 | * | ||
| 633 | * Use 32 to include the \0, and a few extra just in case.. | ||
| 634 | */ | ||
| 635 | strbuf_append_fmt(json, 32, cfg->number_fmt, num); | ||
| 636 | } | ||
| 632 | } | 637 | } |
| 633 | 638 | ||
| 634 | static void json_append_object(lua_State *l, json_config_t *cfg, | 639 | static void json_append_object(lua_State *l, json_config_t *cfg, |
