0
0
mirror of https://github.com/vim/vim.git synced 2025-09-23 03:43:49 -04:00

patch 8.2.3663: using %S in printf() does not work correctly

Problem:    Using %S in printf() does not work correctly.
Solution:   Fix the problem and add more tests. (closes #9208)
This commit is contained in:
presuku
2021-11-24 15:32:57 +00:00
committed by Bram Moolenaar
parent cf1e0239ce
commit 1f2453fec6
3 changed files with 74 additions and 17 deletions

View File

@@ -2143,27 +2143,22 @@ vim_vsnprintf_typval(
}
if (fmt_spec == 'S')
{
size_t base_width = min_field_width;
size_t pad_cell = 0;
char_u *p1;
size_t i;
int cell;
if (precision)
{
char_u *p1;
size_t i = 0;
for (p1 = (char_u *)str_arg; *p1;
for (i = 0, p1 = (char_u *)str_arg; *p1;
p1 += mb_ptr2len(p1))
{
i += (size_t)mb_ptr2cells(p1);
if (i > precision)
break;
}
pad_cell = min_field_width - precision;
base_width = str_arg_l = precision =
p1 - (char_u *)str_arg;
{
cell = mb_ptr2cells(p1);
if (precision_specified && i + cell > precision)
break;
i += cell;
}
str_arg_l = p1 - (char_u *)str_arg;
if (min_field_width != 0)
min_field_width = base_width + pad_cell;
min_field_width += str_arg_l - i;
}
break;