diff options
author | zeertzjq <zeertzjq@outlook.com> | 2025-02-09 08:19:29 +0800 |
---|---|---|
committer | zeertzjq <zeertzjq@outlook.com> | 2025-02-09 08:26:44 +0800 |
commit | 9afc1f0f3b1533bdfa6dd821bbfa93c6858016c6 (patch) | |
tree | 3b3f4ff04f21663af602d59587ce8b1245a88f45 /src/nvim/ops.c | |
parent | 9dc5e2100f679b7523225d23967fc1c87005877b (diff) | |
download | rneovim-9afc1f0f3b1533bdfa6dd821bbfa93c6858016c6.tar.gz rneovim-9afc1f0f3b1533bdfa6dd821bbfa93c6858016c6.tar.bz2 rneovim-9afc1f0f3b1533bdfa6dd821bbfa93c6858016c6.zip |
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 <Bram@vim.org>
Diffstat (limited to 'src/nvim/ops.c')
-rw-r--r-- | src/nvim/ops.c | 15 |
1 files changed, 11 insertions, 4 deletions
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) { |