On 20/03/2018 19:58, hyc(a)symas.com wrote:
> We once discussed padding odd-length keys to make sure the data was still
> word-aligned. Maybe should do that in LMDB 1.0. This particular crash is now
> fixed in mdb.master. I've left other derefs of *fp alone for the moment but
> may need to revisit that later; older ARM and SPARC would probably choke on them.
Yes. Also, as this bug demonstrates, compilers will keep finding
new ways to break over-aligned pointers even on x86. The way to
make sure a compiler cannot deduce that a sub-page is 8- or 4-
byte aligned, is to never create such over-aligned pointer values.
I.e. pass something like struct MDB_pageinfo instead of MDB_page
to anything which may receive a 2-byte-aligned sub-page:
typedef struct MDB_pageinfo {
uint16_t mi_pad, mi_flags;
indx_t mi_lower, mi_upper;
# define MI_OVPAGES(mi) (((unsigned)(mi)->mi_upper<<16) + (mi)->mi_lower)
} MDB_pageinfo;
typedef struct MDB_page {
pgno_t mp_pgno;
MDB_pageinfo mp_info;
indx_t mp_ptrs[1];
} MDB_page;