aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorglepnir <glephunter@gmail.com>2025-06-04 07:22:39 +0800
committerglepnir <glephunter@gmail.com>2025-06-04 13:27:38 +0800
commit97ca92f9ddd751b6863be6b2ebd4491bc229244a (patch)
tree9f8533da6030aa6e8e9a43d00fcf74bd82a6199c /src
parenteb108528044d310c994b967a64375c1b5c4ee770 (diff)
downloadrneovim-97ca92f9ddd751b6863be6b2ebd4491bc229244a.tar.gz
rneovim-97ca92f9ddd751b6863be6b2ebd4491bc229244a.tar.bz2
rneovim-97ca92f9ddd751b6863be6b2ebd4491bc229244a.zip
vim-patch:9.1.1428: completion: register completion needs cleanup
Problem: completion: register completion needs cleanup Solution: slightly refactor get_register_completion() (glepnir) closes: vim/vim#17432 https://github.com/vim/vim/commit/86d46a7018bb648fb27372329e6ddc274051067c Co-authored-by: glepnir <glephunter@gmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/nvim/insexpand.c47
1 files changed, 29 insertions, 18 deletions
diff --git a/src/nvim/insexpand.c b/src/nvim/insexpand.c
index 617e70055b..bc8323e281 100644
--- a/src/nvim/insexpand.c
+++ b/src/nvim/insexpand.c
@@ -4193,6 +4193,7 @@ static int get_next_default_completion(ins_compl_next_state_T *st, pos_T *start_
static void get_register_completion(void)
{
Direction dir = compl_direction;
+ bool adding_mode = compl_status_adding();
for (int i = 0; i < NUM_REGISTERS; i++) {
int regname = get_register_name(i);
@@ -4209,13 +4210,13 @@ static void get_register_completion(void)
continue;
}
- if (compl_status_adding()) {
- for (size_t j = 0; j < reg->y_size; j++) {
- char *str = reg->y_array[j].data;
- if (str == NULL) {
- continue;
- }
+ for (size_t j = 0; j < reg->y_size; j++) {
+ char *str = reg->y_array[j].data;
+ if (str == NULL) {
+ continue;
+ }
+ if (adding_mode) {
int str_len = (int)strlen(str);
if (str_len == 0) {
continue;
@@ -4230,25 +4231,30 @@ static void get_register_completion(void)
dir = FORWARD;
}
}
- }
- } else {
- for (size_t j = 0; j < reg->y_size; j++) {
- char *str = reg->y_array[j].data;
- if (str == NULL) {
- continue;
- }
-
+ } else {
+ // Calculate the safe end of string to avoid null byte issues
+ char *str_end = str + strlen(str);
char *p = str;
- while (*p != NUL) {
+
+ // Safely iterate through the string
+ while (p < str_end && *p != NUL) {
+ char *old_p = p;
p = find_word_start(p);
- if (*p == NUL) {
+ if (p >= str_end || *p == NUL) {
break;
}
char *word_end = find_word_end(p);
- int len = (int)(word_end - p);
- // Add the word to the completion list
+ if (word_end <= p) {
+ word_end = p + utfc_ptr2len(p);
+ }
+
+ if (word_end > str_end) {
+ word_end = str_end;
+ }
+
+ int len = (int)(word_end - p);
if (len > 0 && (!compl_orig_text.data
|| (p_ic ? STRNICMP(p, compl_orig_text.data,
compl_orig_text.size) == 0
@@ -4259,7 +4265,12 @@ static void get_register_completion(void)
dir = FORWARD;
}
}
+
p = word_end;
+
+ if (p <= old_p) {
+ p = old_p + utfc_ptr2len(old_p);
+ }
}
}
}