diff options
author | Jurica Bradaric <jurica.bradaric@avl.com> | 2017-03-07 19:20:07 +0100 |
---|---|---|
committer | Jurica Bradaric <jbradaric@gmail.com> | 2017-03-20 21:40:41 +0100 |
commit | b4cb5fa610903492f89a70d0ae2d4565ddcd1228 (patch) | |
tree | 9544a40910656950dcde49955a676c176f12af37 /src/nvim/strings.c | |
parent | df1e7b7edaf6c2ab9435d3734488c74a278f64a1 (diff) | |
download | rneovim-b4cb5fa610903492f89a70d0ae2d4565ddcd1228.tar.gz rneovim-b4cb5fa610903492f89a70d0ae2d4565ddcd1228.tar.bz2 rneovim-b4cb5fa610903492f89a70d0ae2d4565ddcd1228.zip |
vim-patch:7.4.2266
Problem: printf() test fails on Windows. "-inf" is not used.
Solution: Check for Windows-specific values for "nan". Add sign to "inf"
when appropriate.
https://github.com/vim/vim/commit/9992237a3e791fbc0c1ebf743ece1b75e1488410
Diffstat (limited to 'src/nvim/strings.c')
-rw-r--r-- | src/nvim/strings.c | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/src/nvim/strings.c b/src/nvim/strings.c index d03970108b..47ee311bd4 100644 --- a/src/nvim/strings.c +++ b/src/nvim/strings.c @@ -1209,9 +1209,10 @@ int vim_vsnprintf(char *str, size_t str_m, const char *fmt, va_list ap, } if (fmt_spec == 'f' && abs_f > 1.0e307) { + const char inf_str[] = f < 0 ? "-inf" : "inf"; // avoid a buffer overflow - memmove(tmp, "inf", sizeof("inf")); - str_arg_l = sizeof("inf") - 1; + memmove(tmp, inf_str, sizeof(inf_str) - 1); + str_arg_l = sizeof(inf_str) - 1; } else { format[0] = '%'; int l = 1; @@ -1234,6 +1235,23 @@ int vim_vsnprintf(char *str, size_t str_m, const char *fmt, va_list ap, str_arg_l = (size_t)snprintf(tmp, sizeof(tmp), format, f); assert(str_arg_l < sizeof(tmp)); + // Be consistent: Change "1.#IND" to "nan" and + // "1.#INF" to "inf". + char *s = *tmp == '-' ? tmp + 1 : tmp; + if (STRNCMP(s, "1.#INF", 6) == 0) { + STRCPY(s, "inf"); + } else if (STRNCMP(s, "1.#IND", 6) == 0) { + STRCPY(s, "nan"); + } + // Remove sign before "nan" + if (STRNCMP(tmp, "-nan", 4) == 0) { + STRCPY(tmp, "nan"); + } + // Add sign before "inf" if needed. + if (isinf(f) == -1 && STRNCMP(tmp, "inf", 3) == 0) { + STRCPY(tmp, "-inf"); + } + if (remove_trailing_zeroes) { int i; char *tp; |