Mercurial > vim
comparison src/json.c @ 15446:8ac454818352 v8.1.0731
patch 8.1.0731: JS encoding does not handle negative infinity
commit https://github.com/vim/vim/commit/5f6b379ff3e34297d171635933f907ec80ed4f05
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Jan 12 14:24:27 2019 +0100
patch 8.1.0731: JS encoding does not handle negative infinity
Problem: JS encoding does not handle negative infinity.
Solution: Add support for negative infinity for JS encoding. (Dominique
Pelle, closes #3792)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 12 Jan 2019 14:30:06 +0100 |
parents | de63593896b3 |
children | 1d2b5c016f17 |
comparison
equal
deleted
inserted
replaced
15445:13cc832665ed | 15446:8ac454818352 |
---|---|
314 #ifdef FEAT_FLOAT | 314 #ifdef FEAT_FLOAT |
315 # if defined(HAVE_MATH_H) | 315 # if defined(HAVE_MATH_H) |
316 if (isnan(val->vval.v_float)) | 316 if (isnan(val->vval.v_float)) |
317 ga_concat(gap, (char_u *)"NaN"); | 317 ga_concat(gap, (char_u *)"NaN"); |
318 else if (isinf(val->vval.v_float)) | 318 else if (isinf(val->vval.v_float)) |
319 ga_concat(gap, (char_u *)"Infinity"); | 319 { |
320 if (val->vval.v_float < 0.0) | |
321 ga_concat(gap, (char_u *)"-Infinity"); | |
322 else | |
323 ga_concat(gap, (char_u *)"Infinity"); | |
324 } | |
320 else | 325 else |
321 # endif | 326 # endif |
322 { | 327 { |
323 vim_snprintf((char *)numbuf, NUMBUFLEN, "%g", | 328 vim_snprintf((char *)numbuf, NUMBUFLEN, "%g", |
324 val->vval.v_float); | 329 val->vval.v_float); |
734 } | 739 } |
735 retval = OK; | 740 retval = OK; |
736 break; | 741 break; |
737 | 742 |
738 default: | 743 default: |
739 if (VIM_ISDIGIT(*p) || *p == '-') | 744 if (VIM_ISDIGIT(*p) || (*p == '-' && VIM_ISDIGIT(p[1]))) |
740 { | 745 { |
741 #ifdef FEAT_FLOAT | 746 #ifdef FEAT_FLOAT |
742 char_u *sp = p; | 747 char_u *sp = p; |
743 | 748 |
744 if (*sp == '-') | 749 if (*sp == '-') |
832 cur_item->vval.v_float = NAN; | 837 cur_item->vval.v_float = NAN; |
833 } | 838 } |
834 retval = OK; | 839 retval = OK; |
835 break; | 840 break; |
836 } | 841 } |
842 if (STRNICMP((char *)p, "-Infinity", 9) == 0) | |
843 { | |
844 reader->js_used += 9; | |
845 if (cur_item != NULL) | |
846 { | |
847 cur_item->v_type = VAR_FLOAT; | |
848 cur_item->vval.v_float = -INFINITY; | |
849 } | |
850 retval = OK; | |
851 break; | |
852 } | |
837 if (STRNICMP((char *)p, "Infinity", 8) == 0) | 853 if (STRNICMP((char *)p, "Infinity", 8) == 0) |
838 { | 854 { |
839 reader->js_used += 8; | 855 reader->js_used += 8; |
840 if (cur_item != NULL) | 856 if (cur_item != NULL) |
841 { | 857 { |
849 /* check for truncated name */ | 865 /* check for truncated name */ |
850 len = (int)(reader->js_end - (reader->js_buf + reader->js_used)); | 866 len = (int)(reader->js_end - (reader->js_buf + reader->js_used)); |
851 if ( | 867 if ( |
852 (len < 5 && STRNICMP((char *)p, "false", len) == 0) | 868 (len < 5 && STRNICMP((char *)p, "false", len) == 0) |
853 #ifdef FEAT_FLOAT | 869 #ifdef FEAT_FLOAT |
870 || (len < 9 && STRNICMP((char *)p, "-Infinity", len) == 0) | |
854 || (len < 8 && STRNICMP((char *)p, "Infinity", len) == 0) | 871 || (len < 8 && STRNICMP((char *)p, "Infinity", len) == 0) |
855 || (len < 3 && STRNICMP((char *)p, "NaN", len) == 0) | 872 || (len < 3 && STRNICMP((char *)p, "NaN", len) == 0) |
856 #endif | 873 #endif |
857 || (len < 4 && (STRNICMP((char *)p, "true", len) == 0 | 874 || (len < 4 && (STRNICMP((char *)p, "true", len) == 0 |
858 || STRNICMP((char *)p, "null", len) == 0))) | 875 || STRNICMP((char *)p, "null", len) == 0))) |
1070 * "options" can be JSON_JS or zero. | 1087 * "options" can be JSON_JS or zero. |
1071 * This is only used for testing. | 1088 * This is only used for testing. |
1072 * Return FAIL if the message has a decoding error. | 1089 * Return FAIL if the message has a decoding error. |
1073 * Return MAYBE if the message is truncated, need to read more. | 1090 * Return MAYBE if the message is truncated, need to read more. |
1074 * This only works reliable if the message contains an object, array or | 1091 * This only works reliable if the message contains an object, array or |
1075 * string. A number might be trucated without knowing. | 1092 * string. A number might be truncated without knowing. |
1076 * Does not advance the reader. | 1093 * Does not advance the reader. |
1077 */ | 1094 */ |
1078 int | 1095 int |
1079 json_find_end(js_read_T *reader, int options) | 1096 json_find_end(js_read_T *reader, int options) |
1080 { | 1097 { |