mirror of
https://github.com/neovim/neovim.git
synced 2025-09-12 14:28:18 +00:00
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.
9992237a3e
This commit is contained in:

committed by
Jurica Bradaric

parent
df1e7b7eda
commit
b4cb5fa610
@@ -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) {
|
if (fmt_spec == 'f' && abs_f > 1.0e307) {
|
||||||
|
const char inf_str[] = f < 0 ? "-inf" : "inf";
|
||||||
// avoid a buffer overflow
|
// avoid a buffer overflow
|
||||||
memmove(tmp, "inf", sizeof("inf"));
|
memmove(tmp, inf_str, sizeof(inf_str) - 1);
|
||||||
str_arg_l = sizeof("inf") - 1;
|
str_arg_l = sizeof(inf_str) - 1;
|
||||||
} else {
|
} else {
|
||||||
format[0] = '%';
|
format[0] = '%';
|
||||||
int l = 1;
|
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);
|
str_arg_l = (size_t)snprintf(tmp, sizeof(tmp), format, f);
|
||||||
assert(str_arg_l < sizeof(tmp));
|
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) {
|
if (remove_trailing_zeroes) {
|
||||||
int i;
|
int i;
|
||||||
char *tp;
|
char *tp;
|
||||||
|
@@ -201,12 +201,10 @@ function Test_printf_float()
|
|||||||
|
|
||||||
call assert_equal('inf', printf('%f', 1.0/0.0))
|
call assert_equal('inf', printf('%f', 1.0/0.0))
|
||||||
|
|
||||||
" This prints inf but shouldn't it print -inf instead?
|
call assert_match('^-inf$', printf('%f', -1.0/0.0))
|
||||||
call assert_match('^-\?inf$', printf('%f', -1.0/0.0))
|
|
||||||
|
|
||||||
" This prints -nan but shouldn't it print nan instead?
|
call assert_match('^nan$', printf('%f', sqrt(-1.0)))
|
||||||
call assert_match('^-\?nan$', printf('%f', sqrt(-1.0)))
|
call assert_match('^nan$', printf('%f', 0.0/0.0))
|
||||||
call assert_match('^-\?nan$', printf('%f', 0.0/0.0))
|
|
||||||
|
|
||||||
call assert_fails('echo printf("%f", "a")', 'E807:')
|
call assert_fails('echo printf("%f", "a")', 'E807:')
|
||||||
endfunc
|
endfunc
|
||||||
|
@@ -175,7 +175,7 @@ static int included_patches[] = {
|
|||||||
// 2269,
|
// 2269,
|
||||||
// 2268,
|
// 2268,
|
||||||
// 2267 NA
|
// 2267 NA
|
||||||
// 2266,
|
2266,
|
||||||
2265,
|
2265,
|
||||||
2264,
|
2264,
|
||||||
// 2263,
|
// 2263,
|
||||||
|
Reference in New Issue
Block a user