diff options
author | Bram Moolenaar <Bram@vim.org> | 2020-03-16 20:04:41 +0100 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2020-03-16 20:04:41 +0100 |
commit | 56cb3378727783da2d246b9c5091784821666cfa (patch) | |
tree | e76d3e7264a03f3bd9fc32593717f941655068a2 | |
parent | b2e1f8a28fab71c7ef38d39226967be8c3559590 (diff) | |
download | vim-git-56cb3378727783da2d246b9c5091784821666cfa.tar.gz |
patch 8.2.0392: Coverity warns for using array index out of rangev8.2.0392
Problem: Coverity warns for using array index out of range.
Solution: Add extra "if" to avoid warning.
-rw-r--r-- | src/menu.c | 38 | ||||
-rw-r--r-- | src/version.c | 2 |
2 files changed, 23 insertions, 17 deletions
diff --git a/src/menu.c b/src/menu.c index 8e33cff76..3a9d2e41f 100644 --- a/src/menu.c +++ b/src/menu.c @@ -2877,25 +2877,29 @@ menuitem_getinfo(vimmenu_T *menu, int modes, dict_T *dict) int bit; // Get the first mode in which the menu is available - for (bit = 0; (bit < MENU_MODES) && !((1 << bit) & modes); bit++) + for (bit = 0; bit < MENU_MODES && !((1 << bit) & modes); bit++) ; - if (menu->strings[bit] != NULL) - status = dict_add_string(dict, "rhs", - *menu->strings[bit] == NUL ? - vim_strsave((char_u *)"<Nop>") : - str2special_save(menu->strings[bit], FALSE)); - if (status == OK) - status = dict_add_bool(dict, "noremenu", - menu->noremap[bit] == REMAP_NONE); - if (status == OK) - status = dict_add_bool(dict, "script", - menu->noremap[bit] == REMAP_SCRIPT); - if (status == OK) - status = dict_add_bool(dict, "silent", menu->silent[bit]); - if (status == OK) - status = dict_add_bool(dict, "enabled", - ((menu->enabled & (1 << bit)) != 0)); + if (bit < MENU_MODES) // just in case, avoid Coverity warning + { + if (menu->strings[bit] != NULL) + status = dict_add_string(dict, "rhs", + *menu->strings[bit] == NUL + ? vim_strsave((char_u *)"<Nop>") + : str2special_save(menu->strings[bit], FALSE)); + if (status == OK) + status = dict_add_bool(dict, "noremenu", + menu->noremap[bit] == REMAP_NONE); + if (status == OK) + status = dict_add_bool(dict, "script", + menu->noremap[bit] == REMAP_SCRIPT); + if (status == OK) + status = dict_add_bool(dict, "silent", menu->silent[bit]); + if (status == OK) + status = dict_add_bool(dict, "enabled", + ((menu->enabled & (1 << bit)) != 0)); + } } + // If there are submenus, add all the submenu display names if (status == OK && menu->children != NULL) { diff --git a/src/version.c b/src/version.c index 78d89402a..fdd9d39da 100644 --- a/src/version.c +++ b/src/version.c @@ -739,6 +739,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 392, +/**/ 391, /**/ 390, |