fix: avoid assuming struct packing
lfs_gstate_t was assumed to be a packed array of uint32_t, but this is not always guaranteed. Access the fields directly instead of attempting to loop over an array of uint32_t Fixes clang tidy warnings about use of uninitialized memory accessed.
This commit is contained in:
@@ -404,16 +404,20 @@ struct lfs_diskoff {
|
|||||||
|
|
||||||
// operations on global state
|
// operations on global state
|
||||||
static inline void lfs_gstate_xor(lfs_gstate_t *a, const lfs_gstate_t *b) {
|
static inline void lfs_gstate_xor(lfs_gstate_t *a, const lfs_gstate_t *b) {
|
||||||
for (int i = 0; i < 3; i++) {
|
a->tag ^= b->tag;
|
||||||
((uint32_t*)a)[i] ^= ((const uint32_t*)b)[i];
|
a->pair[0] ^= b->pair[0];
|
||||||
}
|
a->pair[1] ^= b->pair[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline bool lfs_gstate_iszero(const lfs_gstate_t *a) {
|
static inline bool lfs_gstate_iszero(const lfs_gstate_t *a) {
|
||||||
for (int i = 0; i < 3; i++) {
|
if (a->tag != 0) {
|
||||||
if (((uint32_t*)a)[i] != 0) {
|
return false;
|
||||||
return false;
|
}
|
||||||
}
|
if (a->pair[0] != 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (a->pair[1] != 0) {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user