aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/strings.c
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2022-01-16 17:37:06 +0800
committerzeertzjq <zeertzjq@outlook.com>2022-01-16 17:37:06 +0800
commit658ef9c01ee2e89b5a29f8fb018ac959ae2f4a90 (patch)
tree67ff3814fcca6487f8726779975b8f3a530cd499 /src/nvim/strings.c
parent9afefd32d3938a50a023355af86ec3293a047130 (diff)
downloadrneovim-658ef9c01ee2e89b5a29f8fb018ac959ae2f4a90.tar.gz
rneovim-658ef9c01ee2e89b5a29f8fb018ac959ae2f4a90.tar.bz2
rneovim-658ef9c01ee2e89b5a29f8fb018ac959ae2f4a90.zip
vim-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 vim/vim#9208) https://github.com/vim/vim/commit/1f2453fec6f8f0f315f00ca7b562a02090cb1e37
Diffstat (limited to 'src/nvim/strings.c')
-rw-r--r--src/nvim/strings.c27
1 files changed, 11 insertions, 16 deletions
diff --git a/src/nvim/strings.c b/src/nvim/strings.c
index efcd40bb75..291138ef23 100644
--- a/src/nvim/strings.c
+++ b/src/nvim/strings.c
@@ -1001,25 +1001,20 @@ int vim_vsnprintf_typval(char *str, size_t str_m, const char *fmt, va_list ap, t
- str_arg);
}
if (fmt_spec == 'S') {
- size_t base_width = min_field_width;
- size_t pad_cell = 0;
-
- if (precision) {
- char_u *p1;
- size_t i = 0;
-
- for (p1 = (char_u *)str_arg; *p1;
- p1 += utfc_ptr2len(p1)) {
- i += (size_t)utf_ptr2cells(p1);
- if (i > precision) {
- break;
- }
+ char_u *p1;
+ size_t i;
+
+ for (i = 0, p1 = (char_u *)str_arg; *p1; p1 += utfc_ptr2len(p1)) {
+ size_t cell = (size_t)utf_ptr2cells(p1);
+ if (precision_specified && i + cell > precision) {
+ break;
}
- pad_cell = min_field_width - precision;
- base_width = str_arg_l = (size_t)(p1 - (char_u *)str_arg);
+ i += cell;
}
+
+ str_arg_l = (size_t)(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;