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)
diff --git a/src/memline.c b/src/memline.c
index 7cbe559..7acea13 100644
--- a/src/memline.c
+++ b/src/memline.c
@@ -130,7 +130,7 @@
#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 @@
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;
}