aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/eval/encode.c
diff options
context:
space:
mode:
authorZyX <kp-pav@yandex.ru>2016-02-21 21:33:58 +0300
committerZyX <kp-pav@yandex.ru>2016-04-18 02:48:20 +0300
commit406562ac6d3863dfdaedbf40f9d4a23ca37c9ec5 (patch)
tree41ce87f9348c73f8600e736d24a1de17d4114906 /src/nvim/eval/encode.c
parent7cdd01983aeb452e0a3f3eb027e75fe02ce48718 (diff)
downloadrneovim-406562ac6d3863dfdaedbf40f9d4a23ca37c9ec5.tar.gz
rneovim-406562ac6d3863dfdaedbf40f9d4a23ca37c9ec5.tar.bz2
rneovim-406562ac6d3863dfdaedbf40f9d4a23ca37c9ec5.zip
encode: Fail to dump NaN and infinity
Thanks to vim/vim#654
Diffstat (limited to 'src/nvim/eval/encode.c')
-rw-r--r--src/nvim/eval/encode.c21
1 files changed, 18 insertions, 3 deletions
diff --git a/src/nvim/eval/encode.c b/src/nvim/eval/encode.c
index a131f5c3c1..d21347cca6 100644
--- a/src/nvim/eval/encode.c
+++ b/src/nvim/eval/encode.c
@@ -7,6 +7,7 @@
#include <msgpack.h>
#include <inttypes.h>
#include <assert.h>
+#include <math.h>
#include "nvim/eval/encode.h"
#include "nvim/buffer_defs.h" // vimconv_T
@@ -827,9 +828,23 @@ DEFINE_VIML_CONV_FUNCTIONS(, echo, garray_T *const, gap)
#undef CONV_FLOAT
#define CONV_FLOAT(flt) \
do { \
- char numbuf[NUMBUFLEN]; \
- vim_snprintf(numbuf, NUMBUFLEN - 1, "%g", (flt)); \
- ga_concat(gap, numbuf); \
+ const float_T flt_ = (flt); \
+ switch (fpclassify(flt_)) { \
+ case FP_NAN: { \
+ EMSG(_("E474: Unable to represent NaN value in JSON")); \
+ return FAIL; \
+ } \
+ case FP_INFINITE: { \
+ EMSG(_("E474: Unable to represent infinity in JSON")); \
+ return FAIL; \
+ } \
+ default: { \
+ char numbuf[NUMBUFLEN]; \
+ vim_snprintf(numbuf, NUMBUFLEN - 1, "%g", flt_); \
+ ga_concat(gap, (char_u *) numbuf); \
+ break; \
+ } \
+ } \
} while (0)
/// Last used p_enc value