commit 71507281fb86deaaa7f47460e8c7a503b46663f6
parent a5b1b83a2693ffa7a5a0a22b3693d36ea60051be
Author: Devon Gardner <devon@goosur.com>
Date: Sat, 18 Jan 2025 19:49:53 -0500
fix(coverity/530826): validate_opt_idx unchecked negative idx (#32081)
Problem:
opt_idx possible negative value used as index
Solution:
check opt_idx not less than zero (kOptInvalid)
Diffstat:
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/nvim/option.c b/src/nvim/option.c
@@ -980,12 +980,12 @@ static int validate_opt_idx(win_T *win, OptIndex opt_idx, int opt_flags, uint32_
// Skip all options that are not window-local (used when showing
// an already loaded buffer in a window).
- if ((opt_flags & OPT_WINONLY) && (opt_idx == kOptInvalid || !option_is_window_local(opt_idx))) {
+ if ((opt_flags & OPT_WINONLY) && !option_is_window_local(opt_idx)) {
return FAIL;
}
// Skip all options that are window-local (used for :vimgrep).
- if ((opt_flags & OPT_NOWIN) && opt_idx != kOptInvalid && option_is_window_local(opt_idx)) {
+ if ((opt_flags & OPT_NOWIN) && option_is_window_local(opt_idx)) {
return FAIL;
}
@@ -3267,7 +3267,7 @@ bool is_option_hidden(OptIndex opt_idx)
/// Check if option supports a specific type.
bool option_has_type(OptIndex opt_idx, OptValType type)
{
- return options[opt_idx].type == type;
+ return opt_idx != kOptInvalid && options[opt_idx].type == type;
}
/// Check if option supports a specific scope.