diff options
author | presuku <presuku@users.noreply.github.com> | 2021-11-24 15:32:57 +0000 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2021-11-24 15:32:57 +0000 |
commit | 1f2453fec6f8f0f315f00ca7b562a02090cb1e37 (patch) | |
tree | d2717dd4ae150a381d0c3ee1b010dceb62e55c7b /src/strings.c | |
parent | cf1e0239ceec96396fa51f494e442c799ccd45fb (diff) | |
download | vim-git-1f2453fec6f8f0f315f00ca7b562a02090cb1e37.tar.gz |
patch 8.2.3663: using %S in printf() does not work correctlyv8.2.3663
Problem: Using %S in printf() does not work correctly.
Solution: Fix the problem and add more tests. (closes #9208)
Diffstat (limited to 'src/strings.c')
-rw-r--r-- | src/strings.c | 29 |
1 files changed, 12 insertions, 17 deletions
diff --git a/src/strings.c b/src/strings.c index bc88ce5f6..847d74379 100644 --- a/src/strings.c +++ b/src/strings.c @@ -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; |