From 9dc5e2100f679b7523225d23967fc1c87005877b Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 9 Feb 2025 08:11:04 +0800 Subject: vim-patch:8.2.2933: when 'clipboard' is "unnamed" zp does not work correctly Problem: When 'clipboard' is "unnamed" zp and zP do not work correctly. Solution: Pass -1 to str_to_reg() and fix computing the character width instead of using the byte length. (Christian Brabandt, closes vim/vim#8301, closes vim/vim#8317) https://github.com/vim/vim/commit/6e0b553fa12fc5ad5d8ee3d8457e7cb16f38b56f Co-authored-by: Bram Moolenaar --- src/nvim/ops.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/nvim/ops.c b/src/nvim/ops.c index d51b4cc88b..81ce541df4 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -5236,9 +5236,10 @@ static void str_to_reg(yankreg_T *y_ptr, MotionType yank_type, const char *str, // Find the end of each line and save it into the array. if (str_list) { for (char **ss = (char **)str; *ss != NULL; ss++, lnum++) { + int charlen = mb_charlen(*ss); size_t ss_len = strlen(*ss); pp[lnum] = cbuf_to_string(*ss, ss_len); - maxlen = MAX(maxlen, ss_len); + maxlen = MAX(maxlen, (size_t)charlen); } } else { size_t line_len; @@ -5246,8 +5247,11 @@ static void str_to_reg(yankreg_T *y_ptr, MotionType yank_type, const char *str, start < end + extraline; start += line_len + 1, lnum++) { assert(end - start >= 0); - line_len = (size_t)((char *)xmemscan(start, '\n', (size_t)(end - start)) - start); - maxlen = MAX(maxlen, line_len); + const char *line_end = xmemscan(start, '\n', (size_t)(end - start)); + assert(line_end - start >= 0); + line_len = (size_t)(line_end - start); + int charlen = start < end ? mb_charlen_len(start, (int)line_len) : 0; + maxlen = MAX(maxlen, (size_t)charlen); // When appending, copy the previous line and free it after. size_t extra = append ? pp[--lnum].size : 0; -- cgit From 9afc1f0f3b1533bdfa6dd821bbfa93c6858016c6 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 9 Feb 2025 08:19:29 +0800 Subject: vim-patch:8.2.2934: ASAN error when using text from the clipboard Problem: ASAN error when using text from the clipboard. Solution: Get width of each character. https://github.com/vim/vim/commit/24951a67c24e75ec4ff7506f8e2e789ccd786e89 Co-authored-by: Bram Moolenaar --- src/nvim/ops.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/nvim/ops.c b/src/nvim/ops.c index 81ce541df4..cb86d194b8 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -5246,11 +5246,16 @@ static void str_to_reg(yankreg_T *y_ptr, MotionType yank_type, const char *str, for (const char *start = str, *end = str + len; start < end + extraline; start += line_len + 1, lnum++) { - assert(end - start >= 0); - const char *line_end = xmemscan(start, '\n', (size_t)(end - start)); + int charlen = 0; + const char *line_end; + for (line_end = start; line_end < end; line_end++) { + if (*line_end == '\n') { + break; + } + charlen += utf_ptr2cells_len(line_end, (int)(end - line_end)); + } assert(line_end - start >= 0); line_len = (size_t)(line_end - start); - int charlen = start < end ? mb_charlen_len(start, (int)line_len) : 0; maxlen = MAX(maxlen, (size_t)charlen); // When appending, copy the previous line and free it after. @@ -5259,7 +5264,9 @@ static void str_to_reg(yankreg_T *y_ptr, MotionType yank_type, const char *str, if (extra > 0) { memcpy(s, pp[lnum].data, extra); } - memcpy(s + extra, start, line_len); + if (line_len > 0) { + memcpy(s + extra, start, line_len); + } size_t s_len = extra + line_len; if (append) { -- cgit From 00bce2723fb3b6e36bb7b0b0570c33ffc9508b78 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 9 Feb 2025 08:26:48 +0800 Subject: vim-patch:8.2.2935: calculating register width is not always needed Problem: Calculating register width is not always needed. (Christian Brabandt) Solution: Only calculate the width when the type is MBLOCK. https://github.com/vim/vim/commit/6c4c404c580fadd69e39297a6cb4b214f2fcb6d6 Co-authored-by: Bram Moolenaar --- src/nvim/ops.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/nvim/ops.c b/src/nvim/ops.c index cb86d194b8..6c15d9a555 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -5236,10 +5236,11 @@ static void str_to_reg(yankreg_T *y_ptr, MotionType yank_type, const char *str, // Find the end of each line and save it into the array. if (str_list) { for (char **ss = (char **)str; *ss != NULL; ss++, lnum++) { - int charlen = mb_charlen(*ss); - size_t ss_len = strlen(*ss); - pp[lnum] = cbuf_to_string(*ss, ss_len); - maxlen = MAX(maxlen, (size_t)charlen); + pp[lnum] = cstr_to_string(*ss); + if (yank_type == kMTBlockWise) { + size_t charlen = mb_string2cells(*ss); + maxlen = MAX(maxlen, charlen); + } } } else { size_t line_len; @@ -5252,7 +5253,9 @@ static void str_to_reg(yankreg_T *y_ptr, MotionType yank_type, const char *str, if (*line_end == '\n') { break; } - charlen += utf_ptr2cells_len(line_end, (int)(end - line_end)); + if (yank_type == kMTBlockWise) { + charlen += utf_ptr2cells_len(line_end, (int)(end - line_end)); + } } assert(line_end - start >= 0); line_len = (size_t)(line_end - start); -- cgit From 6f0a91579f3b5d30d23420249a74fba432a27a24 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 9 Feb 2025 08:30:58 +0800 Subject: vim-patch:9.1.1083: setreg() doesn't correctly handle mbyte chars in blockwise mode Problem: setreg() doesn't correctly handle mbyte chars in blockwise mode Solution: use mb_ptr2len_len function pointer (Yee Cheng Chin) setreg() will automatically calculate the width when a blockwise mode is specified, but it does not properly calculate the line widths of mbyte characters when value is passed as newline-terminated string. It does work when value is passed as a list of lines though. Fix this by properly using the mbyte function pointer to increment the loop counter. closes: vim/vim#16596 https://github.com/vim/vim/commit/a17f8bfb282805ee8ded014089d3094ef6dbf913 Co-authored-by: Yee Cheng Chin --- src/nvim/ops.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/nvim/ops.c b/src/nvim/ops.c index 6c15d9a555..2491621fbc 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -5248,14 +5248,21 @@ static void str_to_reg(yankreg_T *y_ptr, MotionType yank_type, const char *str, start < end + extraline; start += line_len + 1, lnum++) { int charlen = 0; - const char *line_end; - for (line_end = start; line_end < end; line_end++) { + + const char *line_end = start; + while (line_end < end) { // find the end of the line if (*line_end == '\n') { break; } if (yank_type == kMTBlockWise) { charlen += utf_ptr2cells_len(line_end, (int)(end - line_end)); } + + if (*line_end == NUL) { + line_end++; // registers can have NUL chars + } else { + line_end += utf_ptr2len_len(line_end, (int)(end - line_end)); + } } assert(line_end - start >= 0); line_len = (size_t)(line_end - start); -- cgit