diff options
author | zeertzjq <zeertzjq@outlook.com> | 2022-01-16 17:37:06 +0800 |
---|---|---|
committer | zeertzjq <zeertzjq@outlook.com> | 2022-01-16 17:37:06 +0800 |
commit | 9afefd32d3938a50a023355af86ec3293a047130 (patch) | |
tree | 9d3bad389ef267de8a2b38fd2e4a33dc0f466f27 /src/nvim/strings.c | |
parent | 7085e5b0c8588618e643c87802afc515f67812d9 (diff) | |
download | rneovim-9afefd32d3938a50a023355af86ec3293a047130.tar.gz rneovim-9afefd32d3938a50a023355af86ec3293a047130.tar.bz2 rneovim-9afefd32d3938a50a023355af86ec3293a047130.zip |
vim-patch:8.2.3630: printf() with %S does not handle multi-byte correctly
Problem: Printf() with %S does not handle multi-byte correctly.
Solution: Count cells instead of bytes. (closes vim/vim#9169, closes vim/vim#7486)
https://github.com/vim/vim/commit/d85fccdfed58108c4e0958d0b17c64690b5f073f
Diffstat (limited to 'src/nvim/strings.c')
-rw-r--r-- | src/nvim/strings.c | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/src/nvim/strings.c b/src/nvim/strings.c index e2a8108c45..efcd40bb75 100644 --- a/src/nvim/strings.c +++ b/src/nvim/strings.c @@ -1001,10 +1001,9 @@ int vim_vsnprintf_typval(char *str, size_t str_m, const char *fmt, va_list ap, t - str_arg); } if (fmt_spec == 'S') { - if (min_field_width != 0) { - min_field_width += (strlen(str_arg) - - mb_string2cells((char_u *)str_arg)); - } + size_t base_width = min_field_width; + size_t pad_cell = 0; + if (precision) { char_u *p1; size_t i = 0; @@ -1016,7 +1015,11 @@ int vim_vsnprintf_typval(char *str, size_t str_m, const char *fmt, va_list ap, t break; } } - str_arg_l = (size_t)(p1 - (char_u *)str_arg); + pad_cell = min_field_width - precision; + base_width = str_arg_l = (size_t)(p1 - (char_u *)str_arg); + } + if (min_field_width != 0) { + min_field_width = base_width + pad_cell; } } break; |