Mercurial > vim
changeset 19671:897cb43a5c72 v8.2.0392
patch 8.2.0392: Coverity warns for using array index out of range
Commit: https://github.com/vim/vim/commit/56cb3378727783da2d246b9c5091784821666cfa
Author: Bram Moolenaar <Bram@vim.org>
Date: Mon Mar 16 20:04:41 2020 +0100
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.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Mon, 16 Mar 2020 20:15:04 +0100 |
parents | 00e4b686ae2b |
children | 97aa56fab5a3 |
files | src/menu.c src/version.c |
diffstat | 2 files changed, 23 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- a/src/menu.c +++ b/src/menu.c @@ -2877,25 +2877,29 @@ menuitem_getinfo(vimmenu_T *menu, int mo 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) {