vim-patch:8.1.1827: allocating more memory than needed for extended structs (#22081)

Problem:    Allocating more memory than needed for extended structs.
Solution:   Use offsetof() instead of sizeof(). (Dominique Pelle,
            closes vim/vim#4786)

47ed553fd5
This commit is contained in:
zeertzjq
2023-02-01 18:07:09 +08:00
committed by GitHub
parent d63ad600e0
commit 01d3a64e28
5 changed files with 7 additions and 7 deletions

View File

@@ -3736,7 +3736,7 @@ static void add_keyword(char *const name, const int id, const int flags,
sizeof(name_folded))
: name;
keyentry_T *const kp = xmalloc(sizeof(keyentry_T) + strlen(name_ic));
keyentry_T *const kp = xmalloc(offsetof(keyentry_T, keyword) + strlen(name_ic) + 1);
STRCPY(kp->keyword, name_ic);
kp->k_syn.id = (int16_t)id;
kp->k_syn.inc_tag = current_syn_inc_tag;