Initializing the individual bit field members leaves the remaining two
bits uninitialized and that garbage state gets persisted.
In general, using bit fields in a structure where the layout actually
matters is not desirable. Even with a few single bits, such as here,
their order, strictly speaking, is not guaranteed:
An implementation may allocate any addressable storage unit large
enough to hold a bit-field. If enough space remains, a bit-field
that immediately follows another bit-field in a structure shall be
packed into adjacent bits of the same unit. If insufficient space
remains, whether a bit-field that does not fit is put into the next
unit or overlaps adjacent units is implementation-defined. The
order of allocation of bit-fields within a unit (high-order to
low-order or low-order to high-order) is implementation-defined.
The alignment of the addressable storage unit is unspecified.
Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
(cherry picked from commit
91d270b210a908ea2f3578dd7db3263383da95a8)
uint64_t write_data_pos = 0; /* SSD data offset */
#endif
union {
- uint8_t flags;
+ uint8_t flags = 0;
struct {
uint8_t entry_valid :1; /* if 0, this entry is free */
uint8_t sync_point :1; /* No data. No write sequence number. Marks sync
uint32_t entry_index = 0; /* For debug consistency check. Can be removed if
* we need the space */
WriteLogCacheEntry(uint64_t image_offset_bytes=0, uint64_t write_bytes=0)
- : image_offset_bytes(image_offset_bytes), write_bytes(write_bytes),
- entry_valid(0), sync_point(0), sequenced(0), has_data(0), discard(0), writesame(0) {
- }
+ : image_offset_bytes(image_offset_bytes), write_bytes(write_bytes) {}
BlockExtent block_extent();
uint64_t get_offset_bytes();
uint64_t get_write_bytes();