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

@@ -2514,7 +2514,7 @@ static void store_sb_text(char **sb_str, char *s, int attr, int *sb_col, int fin
}
if (s > *sb_str) {
mp = xmalloc((sizeof(msgchunk_T) + (size_t)(s - *sb_str)));
mp = xmalloc(offsetof(msgchunk_T, sb_text) + (size_t)(s - *sb_str) + 1);
mp->sb_eol = (char)finish;
mp->sb_msg_col = *sb_col;
mp->sb_attr = attr;