0
0
mirror of https://github.com/vim/vim.git synced 2025-09-27 04:14:06 -04:00

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.
This commit is contained in:
Bram Moolenaar
2016-08-27 15:26:35 +02:00
parent 76efafba2a
commit 9992237a3e
3 changed files with 32 additions and 7 deletions

View File

@@ -4701,6 +4701,7 @@ vim_vsnprintf(
char format[40]; char format[40];
int l; int l;
int remove_trailing_zeroes = FALSE; int remove_trailing_zeroes = FALSE;
char *s;
f = f =
# if defined(FEAT_EVAL) # if defined(FEAT_EVAL)
@@ -4730,9 +4731,17 @@ vim_vsnprintf(
) )
{ {
/* Avoid a buffer overflow */ /* Avoid a buffer overflow */
if (f < 0)
{
strcpy(tmp, "-inf");
str_arg_l = 4;
}
else
{
strcpy(tmp, "inf"); strcpy(tmp, "inf");
str_arg_l = 3; str_arg_l = 3;
} }
}
else else
{ {
format[0] = '%'; format[0] = '%';
@@ -4753,6 +4762,22 @@ vim_vsnprintf(
format[l + 1] = NUL; format[l + 1] = NUL;
str_arg_l = sprintf(tmp, format, f); str_arg_l = sprintf(tmp, format, f);
/* Be consistent: Change "1.#IND" to "nan" and
* "1.#INF" to "inf". */
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;

View File

@@ -204,12 +204,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:')
endif endif

View File

@@ -763,6 +763,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
2266,
/**/ /**/
2265, 2265,
/**/ /**/