From ffafb9cbb106c8e890a9949b49033e6deee44863 Mon Sep 17 00:00:00 2001 From: Joakim Plate Date: Tue, 11 Mar 2025 16:19:58 +0100 Subject: [PATCH] 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. --- lfs.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/lfs.c b/lfs.c index 7520f2ea..901d712e 100644 --- a/lfs.c +++ b/lfs.c @@ -404,16 +404,20 @@ struct lfs_diskoff { // operations on global state static inline void lfs_gstate_xor(lfs_gstate_t *a, const lfs_gstate_t *b) { - for (int i = 0; i < 3; i++) { - ((uint32_t*)a)[i] ^= ((const uint32_t*)b)[i]; - } + a->tag ^= b->tag; + a->pair[0] ^= b->pair[0]; + a->pair[1] ^= b->pair[1]; } static inline bool lfs_gstate_iszero(const lfs_gstate_t *a) { - for (int i = 0; i < 3; i++) { - if (((uint32_t*)a)[i] != 0) { - return false; - } + if (a->tag != 0) { + return false; + } + if (a->pair[0] != 0) { + return false; + } + if (a->pair[1] != 0) { + return false; } return true; }