Redmine #6214: Fix memory alignment errors when using LMDB/NextDB().

This was causing SPARC architecture to crash when expecting a struct
in the value, since the struct would be aligned to a byte position
which depended on the length of the key. x86 is also slower when
accessing unaligned data types, so should be an improvement there as
well.
It's simpler to read. Modulo is an expensive instruction, but given that we call malloc, I doubt it matters much in this case. Do you prefer that I change it?