0
0
mirror of https://github.com/vim/vim.git synced 2025-10-17 07:44:28 -04:00

patch 9.0.1271: using sizeof() and subtract array size is tricky

Problem:    Using sizeof() and subtract array size is tricky.
Solution:   Use offsetof() instead. (closes #11926)
This commit is contained in:
zeertzjq
2023-02-01 13:11:15 +00:00
committed by Bram Moolenaar
parent a7d36b7320
commit 1b438a8228
10 changed files with 15 additions and 11 deletions

View File

@@ -130,7 +130,7 @@ struct data_block
#define DB_INDEX_MASK (~DB_MARKED)
#define INDEX_SIZE (sizeof(unsigned)) // size of one db_index entry
#define HEADER_SIZE (sizeof(DATA_BL) - INDEX_SIZE) // size of data block header
#define HEADER_SIZE (offsetof(DATA_BL, db_index)) // size of data block header
#define B0_FNAME_SIZE_ORG 900 // what it was in older versions
#define B0_FNAME_SIZE_NOCRYPT 898 // 2 bytes used for other things
@@ -4162,8 +4162,9 @@ ml_new_ptr(memfile_T *mfp)
pp = (PTR_BL *)(hp->bh_data);
pp->pb_id = PTR_ID;
pp->pb_count = 0;
pp->pb_count_max = (short_u)((mfp->mf_page_size - sizeof(PTR_BL))
/ sizeof(PTR_EN) + 1);
pp->pb_count_max =
(short_u)((mfp->mf_page_size - offsetof(PTR_BL, pb_pointer))
/ sizeof(PTR_EN));
return hp;
}