Skip to content

Commit 8ed63b2

Browse files
authored
Merge pull request #1084 from elupus/fix/packing
fix: avoid assuming struct packing
2 parents a666730 + 61a1b0b commit 8ed63b2

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

lfs.c

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -404,18 +404,15 @@ struct lfs_diskoff {
404404

405405
// operations on global state
406406
static inline void lfs_gstate_xor(lfs_gstate_t *a, const lfs_gstate_t *b) {
407-
for (int i = 0; i < 3; i++) {
408-
((uint32_t*)a)[i] ^= ((const uint32_t*)b)[i];
409-
}
407+
a->tag ^= b->tag;
408+
a->pair[0] ^= b->pair[0];
409+
a->pair[1] ^= b->pair[1];
410410
}
411411

412412
static inline bool lfs_gstate_iszero(const lfs_gstate_t *a) {
413-
for (int i = 0; i < 3; i++) {
414-
if (((uint32_t*)a)[i] != 0) {
415-
return false;
416-
}
417-
}
418-
return true;
413+
return a->tag == 0
414+
&& a->pair[0] == 0
415+
&& a->pair[1] == 0;
419416
}
420417

421418
#ifndef LFS_READONLY

0 commit comments

Comments
 (0)