From fd62ef96748184f2fab6a158633dd493e45c5d82 Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Mon, 3 Feb 2025 03:07:30 -0600 Subject: [PATCH] Made lfsr_bshrub_init a bit safer We don't strictly need to initialize all of the shrub fields, but the path of bnulls -> bshrubs -> btrees in the file logic is complex. It's highly likely leaving these uninitialized will cause bugs in the future. This does come with a small code cost, but better safe than sorry: code stack ctx before: 36436 2608 640 after: 36476 (+0.1%) 2608 (+0.0%) 640 (+0.0%) --- lfs.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lfs.c b/lfs.c index 260356be..84a8b244 100644 --- a/lfs.c +++ b/lfs.c @@ -6131,7 +6131,10 @@ static int lfsr_shrub_commit(lfs_t *lfs, lfsr_rbyd_t *rbyd_, // create a non-existant bshrub static void lfsr_bshrub_init(lfsr_bshrub_t *bshrub) { bshrub->weight = 0; + bshrub->blocks[0] = -1; bshrub->trunk = 0; + // force estimate recalculation + bshrub->eoff = -1; } static inline bool lfsr_bshrub_isbnull(const lfsr_bshrub_t *bshrub) {