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

@@ -252,7 +252,7 @@ static void add_buff(buffheader_T *const buf, const char *const s, ptrdiff_t sle
} else {
len = (size_t)slen;
}
buffblock_T *p = xmalloc(sizeof(buffblock_T) + len);
buffblock_T *p = xmalloc(offsetof(buffblock_T, b_str) + len + 1);
buf->bh_space = len - (size_t)slen;
xstrlcpy(p->b_str, s, (size_t)slen + 1);