aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames McCoy <jamessan@jamessan.com>2017-08-15 19:55:24 -0400
committerGitHub <noreply@github.com>2017-08-15 19:55:24 -0400
commit30cb66e8ba520d4564189ff763b5859e3d80581f (patch)
treef3795b5d8097f6488fcb09bb40f5a139913b1509
parentbb70eec17782501db35683f48136fcced9eae259 (diff)
parent1f4090011ef95e2bdf217405d28a1b48300965bd (diff)
downloadrneovim-30cb66e8ba520d4564189ff763b5859e3d80581f.tar.gz
rneovim-30cb66e8ba520d4564189ff763b5859e3d80581f.tar.bz2
rneovim-30cb66e8ba520d4564189ff763b5859e3d80581f.zip
Merge pull request #7168 from teto/fix_coverty
Closes #7149
-rw-r--r--src/nvim/mbyte.h3
-rw-r--r--src/nvim/menu.c8
2 files changed, 6 insertions, 5 deletions
diff --git a/src/nvim/mbyte.h b/src/nvim/mbyte.h
index 02c6065672..bf6ccb13a5 100644
--- a/src/nvim/mbyte.h
+++ b/src/nvim/mbyte.h
@@ -19,6 +19,9 @@
#define MB_BYTE2LEN(b) utf8len_tab[b]
#define MB_BYTE2LEN_CHECK(b) (((b) < 0 || (b) > 255) ? 1 : utf8len_tab[b])
+// max length of an unicode char
+#define MB_MAXCHAR 6
+
/* properties used in enc_canon_table[] (first three mutually exclusive) */
#define ENC_8BIT 0x01
#define ENC_DBCS 0x02
diff --git a/src/nvim/menu.c b/src/nvim/menu.c
index a498916e5e..0db250d111 100644
--- a/src/nvim/menu.c
+++ b/src/nvim/menu.c
@@ -666,8 +666,6 @@ static void free_menu_string(vimmenu_T *menu, int idx)
static dict_T *menu_get_recursive(const vimmenu_T *menu, int modes)
{
dict_T *dict;
- char buf[sizeof(menu->mnemonic)];
- int mnemonic_len;
if (!menu || (menu->modes & modes) == 0x0) {
return NULL;
@@ -679,8 +677,8 @@ static dict_T *menu_get_recursive(const vimmenu_T *menu, int modes)
tv_dict_add_nr(dict, S_LEN("hidden"), menu_is_hidden(menu->dname));
if (menu->mnemonic) {
- mnemonic_len = utf_char2bytes(menu->mnemonic, (u_char *)buf);
- buf[mnemonic_len] = '\0';
+ char buf[MB_MAXCHAR + 1] = { 0 }; // > max value of utf8_char2bytes
+ utf_char2bytes(menu->mnemonic, (char_u *)buf);
tv_dict_add_str(dict, S_LEN("shortcut"), buf);
}
@@ -717,7 +715,7 @@ static dict_T *menu_get_recursive(const vimmenu_T *menu, int modes)
list_T *children_list = tv_list_alloc();
for (menu = menu->children; menu != NULL; menu = menu->next) {
dict_T *dic = menu_get_recursive(menu, modes);
- if (dict && tv_dict_len(dict) > 0) {
+ if (tv_dict_len(dict) > 0) {
tv_list_append_dict(children_list, dic);
}
}