aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/nvim/option.c23
1 files changed, 18 insertions, 5 deletions
diff --git a/src/nvim/option.c b/src/nvim/option.c
index 9942d154e1..b7521e38f8 100644
--- a/src/nvim/option.c
+++ b/src/nvim/option.c
@@ -4286,10 +4286,10 @@ static void check_redraw(uint32_t flags)
}
/*
- * Find index for option 'arg'.
+ * Find index for option 'arg' that has given length.
* Return -1 if not found.
*/
-static int findoption(char_u *arg)
+static int findoption_len(const char_u *const arg, const size_t len)
{
char *s, *p;
static short quick_tab[27] = {0, 0}; /* quick access table */
@@ -4313,6 +4313,8 @@ static int findoption(char_u *arg)
}
}
+ assert(len > 0);
+
/*
* Check for name starting with an illegal character.
*/
@@ -4320,20 +4322,22 @@ static int findoption(char_u *arg)
return -1;
int opt_idx;
- is_term_opt = (arg[0] == 't' && arg[1] == '_');
+ is_term_opt = (len > 2 && arg[0] == 't' && arg[1] == '_');
if (is_term_opt)
opt_idx = quick_tab[26];
else
opt_idx = quick_tab[CharOrdLow(arg[0])];
+ // Match full name
for (; (s = options[opt_idx].fullname) != NULL; opt_idx++) {
- if (STRCMP(arg, s) == 0) /* match full name */
+ if (STRNCMP(arg, s, len) == 0 && s[len] == NUL)
break;
}
if (s == NULL && !is_term_opt) {
opt_idx = quick_tab[CharOrdLow(arg[0])];
+ // Match short name
for (; options[opt_idx].fullname != NULL; opt_idx++) {
s = options[opt_idx].shortname;
- if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
+ if (s != NULL && STRNCMP(arg, s, len) == 0 && s[len] == NUL)
break;
s = NULL;
}
@@ -4402,6 +4406,15 @@ bool set_tty_option(char *name, char *value)
}
/*
+ * Find index for option 'arg'.
+ * Return -1 if not found.
+ */
+static int findoption(char_u *arg)
+{
+ return findoption_len(arg, STRLEN(arg));
+}
+
+/*
* Get the value for an option.
*
* Returns: