diff options
author | zeertzjq <zeertzjq@outlook.com> | 2025-03-19 07:08:39 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-03-19 07:08:39 +0800 |
commit | 4d83649d1022a8956660b4ae83c28998cabfcfca (patch) | |
tree | e0dd9cb2bc3f66f9449e29d47c9ed8d53b3ba032 | |
parent | 62d9fab9af21323e42828748e6761c02020a7aa5 (diff) | |
download | rneovim-4d83649d1022a8956660b4ae83c28998cabfcfca.tar.gz rneovim-4d83649d1022a8956660b4ae83c28998cabfcfca.tar.bz2 rneovim-4d83649d1022a8956660b4ae83c28998cabfcfca.zip |
vim-patch:9.1.1222: using wrong length for last inserted string (#32975)
Problem: using wrong length for last inserted string
(Christ van Willegen, after v9.1.1212)
Solution: use the correct length in get_last_insert_save(), make
get_last_insert() return a string_T (John Marriott)
closes: vim/vim#16921
https://github.com/vim/vim/commit/8ac0f73eb1e0e6128dd21eb294d12b83b615f05a
N/A patches:
vim-patch:9.1.1129: missing out-of-memory test in buf_write()
vim-patch:9.1.1218: missing out-of-memory check in filepath.c
Co-authored-by: John Marriott <basilisk@internode.on.net>
-rw-r--r-- | src/nvim/edit.c | 46 | ||||
-rw-r--r-- | src/nvim/ops.c | 3 |
2 files changed, 21 insertions, 28 deletions
diff --git a/src/nvim/edit.c b/src/nvim/edit.c index a81d1416f1..c342764ced 100644 --- a/src/nvim/edit.c +++ b/src/nvim/edit.c @@ -2696,8 +2696,8 @@ int stuff_inserted(int c, int count, int no_esc) { char last = NUL; - String *insert = get_last_insert(); // text to be inserted - if (insert->data == NULL) { + String insert = get_last_insert(); // text to be inserted + if (insert.data == NULL) { emsg(_(e_noinstext)); return FAIL; } @@ -2707,30 +2707,30 @@ int stuff_inserted(int c, int count, int no_esc) stuffcharReadbuff(c); } - if (insert->size > 0) { + if (insert.size > 0) { // look for the last ESC in 'insert' - for (char *p = insert->data + insert->size - 1; p >= insert->data; p--) { + for (char *p = insert.data + insert.size - 1; p >= insert.data; p--) { if (*p == ESC) { - insert->size = (size_t)(p - insert->data); + insert.size = (size_t)(p - insert.data); break; } } } - if (insert->size > 0) { - char *p = insert->data + insert->size - 1; + if (insert.size > 0) { + char *p = insert.data + insert.size - 1; // when the last char is either "0" or "^" it will be quoted if no ESC // comes after it OR if it will inserted more than once and "ptr" // starts with ^D. -- Acevedo if ((*p == '0' || *p == '^') - && (no_esc || (*insert->data == Ctrl_D && count > 1))) { + && (no_esc || (*insert.data == Ctrl_D && count > 1))) { last = *p; - insert->size--; + insert.size--; } } do { - stuffReadbuffLen(insert->data, (ptrdiff_t)insert->size); + stuffReadbuffLen(insert.data, (ptrdiff_t)insert.size); // A trailing "0" is inserted as "<C-V>048", "^" as "<C-V>^". switch (last) { case '0': @@ -2752,36 +2752,28 @@ int stuff_inserted(int c, int count, int no_esc) return OK; } -String *get_last_insert(void) +String get_last_insert(void) FUNC_ATTR_PURE { - static String insert = STRING_INIT; - - insert = last_insert.data == NULL ? NULL_STRING : (String){ - insert.data = last_insert.data + last_insert_skip, - insert.size = last_insert.size - (size_t)last_insert_skip, + return last_insert.data == NULL ? NULL_STRING : (String){ + .data = last_insert.data + last_insert_skip, + .size = last_insert.size - (size_t)last_insert_skip, }; - - return &insert; } // Get last inserted string, and remove trailing <Esc>. // Returns pointer to allocated memory (must be freed) or NULL. char *get_last_insert_save(void) { - String *insert = get_last_insert(); + String insert = get_last_insert(); - if (insert->data == NULL) { + if (insert.data == NULL) { return NULL; } - char *s = xmemdupz(insert->data, insert->size); - if (insert->size > 0) { - // remain trailing ESC - insert->size--; - if (s[insert->size] == ESC) { - s[insert->size] = NUL; - } + char *s = xmemdupz(insert.data, insert.size); + if (insert.size > 0 && s[insert.size - 1] == ESC) { // remain trailing ESC + s[insert.size - 1] = NUL; } return s; } diff --git a/src/nvim/ops.c b/src/nvim/ops.c index cac811820b..977d26890e 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -3849,7 +3849,8 @@ void ex_display(exarg_T *eap) } // display last inserted text - if ((p = get_last_insert()->data) != NULL + String insert = get_last_insert(); + if ((p = insert.data) != NULL && (arg == NULL || vim_strchr(arg, '.') != NULL) && !got_int && !message_filtered(p)) { msg_puts("\n c \". "); |