aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2022-08-05 06:26:35 +0800
committerzeertzjq <zeertzjq@outlook.com>2022-08-05 06:47:24 +0800
commit93649cefab4d6864f21a1278e4cde076daf6adbc (patch)
tree21c776d8c58ececfcbd4243b2465ff7b56053eb3
parent77926b64938fb0c7a9581edbb486b712b29dafac (diff)
downloadrneovim-93649cefab4d6864f21a1278e4cde076daf6adbc.tar.gz
rneovim-93649cefab4d6864f21a1278e4cde076daf6adbc.tar.bz2
rneovim-93649cefab4d6864f21a1278e4cde076daf6adbc.zip
vim-patch:8.2.0392: Coverity warns for using array index out of range
Problem: Coverity warns for using array index out of range. Solution: Add extra "if" to avoid warning. https://github.com/vim/vim/commit/56cb3378727783da2d246b9c5091784821666cfa
-rw-r--r--src/nvim/menu.c22
1 files changed, 12 insertions, 10 deletions
diff --git a/src/nvim/menu.c b/src/nvim/menu.c
index 6311d5dddc..58e4e634c4 100644
--- a/src/nvim/menu.c
+++ b/src/nvim/menu.c
@@ -1913,16 +1913,18 @@ static void menuitem_getinfo(const vimmenu_T *menu, int modes, dict_T *dict)
// Get the first mode in which the menu is available
for (bit = 0; (bit < MENU_MODES) && !((1 << bit) & modes); bit++) {}
- if (menu->strings[bit] != NULL) {
- tv_dict_add_allocated_str(dict, S_LEN("rhs"),
- *menu->strings[bit] == NUL
- ? xstrdup("<Nop>")
- : str2special_save(menu->strings[bit], false, false));
- }
- tv_dict_add_bool(dict, S_LEN("noremenu"), menu->noremap[bit] == REMAP_NONE);
- tv_dict_add_bool(dict, S_LEN("script"), menu->noremap[bit] == REMAP_SCRIPT);
- tv_dict_add_bool(dict, S_LEN("silent"), menu->silent[bit]);
- tv_dict_add_bool(dict, S_LEN("enabled"), (menu->enabled & (1 << bit)) != 0);
+ if (bit < MENU_MODES) { // just in case, avoid Coverity warning
+ if (menu->strings[bit] != NULL) {
+ tv_dict_add_allocated_str(dict, S_LEN("rhs"),
+ *menu->strings[bit] == NUL
+ ? xstrdup("<Nop>")
+ : str2special_save(menu->strings[bit], false, false));
+ }
+ tv_dict_add_bool(dict, S_LEN("noremenu"), menu->noremap[bit] == REMAP_NONE);
+ tv_dict_add_bool(dict, S_LEN("script"), menu->noremap[bit] == REMAP_SCRIPT);
+ tv_dict_add_bool(dict, S_LEN("silent"), menu->silent[bit]);
+ tv_dict_add_bool(dict, S_LEN("enabled"), (menu->enabled & (1 << bit)) != 0);
+ }
} else {
// If there are submenus, add all the submenu display names
list_T *const l = tv_list_alloc(kListLenMayKnow);