vim-patch:9.0.1271: using sizeof() and subtract array size is tricky (#22087)

Problem:    Using sizeof() and subtract array size is tricky.
Solution:   Use offsetof() instead. (closes vim/vim#11926)

1b438a8228
This commit is contained in:
zeertzjq
2023-02-01 21:53:32 +08:00
committed by GitHub
parent a26c0ecab6
commit 4cc0d6b854
8 changed files with 10 additions and 9 deletions

View File

@@ -1745,7 +1745,7 @@ void count_common_word(slang_T *lp, char *word, int len, uint8_t count)
const size_t p_len = strlen(p);
hashitem_T *hi = hash_lookup(&lp->sl_wordcount, (const char *)p, p_len, hash);
if (HASHITEM_EMPTY(hi)) {
wc = xmalloc(sizeof(wordcount_T) + p_len);
wc = xmalloc(offsetof(wordcount_T, wc_word) + p_len + 1);
memcpy(wc->wc_word, p, p_len + 1);
wc->wc_count = count;
hash_add_item(&lp->sl_wordcount, hi, (char *)wc->wc_word, hash);