patch 9.1.1222: using wrong length for last inserted string Commit: https://github.com/vim/vim/commit/8ac0f73eb1e0e6128dd21eb294d12b83b615f05a Author: John Marriott <basil...@internode.on.net> Date: Tue Mar 18 20:49:01 2025 +0100
patch 9.1.1222: using wrong length for last inserted string 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: #16921 Signed-off-by: John Marriott <basil...@internode.on.net> Signed-off-by: Christian Brabandt <c...@256bit.org> diff --git a/src/edit.c b/src/edit.c index 143a4ce3c..a2a004c12 100644 --- a/src/edit.c +++ b/src/edit.c @@ -2916,11 +2916,11 @@ stuff_inserted( long count, // Repeat this many times int no_esc) // Don't add an ESC at the end { - string_T *insert; // text to be inserted + string_T insert; // text to be inserted char_u last = ' '; insert = get_last_insert(); - if (insert->string == NULL) + if (insert.string == NULL) { emsg(_(e_no_inserted_text_yet)); return FAIL; @@ -2930,39 +2930,39 @@ stuff_inserted( if (c != NUL) stuffcharReadbuff(c); - if (insert->length > 0) + if (insert.length > 0) { char_u *p; // look for the last ESC in 'insert' - for (p = insert->string + insert->length - 1; p >= insert->string; --p) + for (p = insert.string + insert.length - 1; p >= insert.string; --p) { if (*p == ESC) { - insert->length = (size_t)(p - insert->string); + insert.length = (size_t)(p - insert.string); break; } } } - if (insert->length > 0) + if (insert.length > 0) { - char_u *p = insert->string + insert->length - 1; + char_u *p = insert.string + insert.length - 1; // when the last char is either "0" or "^" it will be quoted if no ESC // comes after it OR if it will insert more than once and "ptr" // starts with ^D. -- Acevedo if ((*p == '0' || *p == '^') - && (no_esc || (*insert->string == Ctrl_D && count > 1))) + && (no_esc || (*insert.string == Ctrl_D && count > 1))) { last = *p; - --insert->length; + --insert.length; } } do { - stuffReadbuffLen(insert->string, insert->length); + stuffReadbuffLen(insert.string, insert.length); // a trailing "0" is inserted as "<C-V>048", "^" as "<C-V>^" switch (last) { @@ -2991,23 +2991,18 @@ stuff_inserted( return OK; } - string_T * + string_T get_last_insert(void) { - static string_T insert = {NULL, 0}; + string_T insert = {NULL, 0}; - if (last_insert.string == NULL) - { - insert.string = NULL; - insert.length = 0; - } - else + if (last_insert.string != NULL) { insert.string = last_insert.string + last_insert_skip; insert.length = (size_t)(last_insert.length - last_insert_skip); } - return &insert; + return insert; } /* @@ -3017,22 +3012,17 @@ get_last_insert(void) char_u * get_last_insert_save(void) { - string_T *insert = get_last_insert(); + string_T insert = get_last_insert(); char_u *s; - if (insert->string == NULL) + if (insert.string == NULL) return NULL; - s = vim_strnsave(insert->string, insert->length); + s = vim_strnsave(insert.string, insert.length); if (s == NULL) return NULL; - if (insert->length > 0) - { - // remove trailing ESC - --insert->length; - if (s[insert->length] == ESC) - s[insert->length] = NUL; - } + if (insert.length > 0 && s[insert.length - 1] == ESC) // remove trailing ESC + s[insert.length - 1] = NUL; return s; } diff --git a/src/proto/edit.pro b/src/proto/edit.pro index 170ac978c..6b2b75a74 100644 --- a/src/proto/edit.pro +++ b/src/proto/edit.pro @@ -24,7 +24,7 @@ int cursor_up(long n, int upd_topline); void cursor_down_inner(win_T *wp, long n); int cursor_down(long n, int upd_topline); int stuff_inserted(int c, long count, int no_esc); -string_T *get_last_insert(void); +string_T get_last_insert(void); char_u *get_last_insert_save(void); void replace_push(int c); int replace_push_mb(char_u *p); diff --git a/src/register.c b/src/register.c index 1674a1260..267e0fcc4 100644 --- a/src/register.c +++ b/src/register.c @@ -2379,6 +2379,7 @@ ex_display(exarg_T *eap) char_u *arg = eap->arg; int clen; int type; + string_T insert; if (arg != NULL && *arg == NUL) arg = NULL; @@ -2471,7 +2472,8 @@ ex_display(exarg_T *eap) } // display last inserted text - if ((p = get_last_insert()->string) != NULL + insert = get_last_insert(); + if ((p = insert.string) != NULL && (arg == NULL || vim_strchr(arg, '.') != NULL) && !got_int && !message_filtered(p)) { diff --git a/src/version.c b/src/version.c index 12a7f4538..ee5b5ed7f 100644 --- a/src/version.c +++ b/src/version.c @@ -704,6 +704,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 1222, /**/ 1221, /**/ -- -- You received this message from the "vim_dev" maillist. Do not top-post! Type your reply below the text you are replying to. For more information, visit http://www.vim.org/maillist.php --- You received this message because you are subscribed to the Google Groups "vim_dev" group. To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+unsubscr...@googlegroups.com. To view this discussion visit https://groups.google.com/d/msgid/vim_dev/E1tud6a-0017iJ-ES%40256bit.org.