valgrind: Fixed uninitialized read when truncating fragment leaf

Valgrind was reporting a conditional move on uninitialized read here,
which is correct. If we fetch a data fragment during a read, the
cksize/cksum is meaningless and may be uninitialized.

This was somewhat intentional as both lfs3_bptr_claim and LFS3_o_UNCRYST
are inconsequential when file->leaf is a data fragment. Why bother
checking for a condition that doesn't matter?

But keeping Valgrind happy is significantly more important for
everyone's mental health.

Costs an extra 4 bytes of code:

           code          stack          ctx
  before: 35256           2136          660
  after:  35260 (+0.0%)   2136 (+0.0%)  660 (+0.0%)
This commit is contained in:
Christopher Haster
2026-02-04 17:46:18 -06:00
parent 0ea11c1a0e
commit 7397605517
+4 -3
View File
@@ -14767,9 +14767,10 @@ int lfs3_file_truncate(lfs3_t *lfs3, lfs3_file_t *file, lfs3_off_t size_) {
size_ - lfs3_min(file->leaf.pos, size_));
file->leaf.pos = lfs3_min(file->leaf.pos, size_);
// mark as crystallized if this truncates our erased-state
if (lfs3_bptr_off(&file->leaf.bptr)
+ lfs3_bptr_size(&file->leaf.bptr)
< lfs3_bptr_cksize(&file->leaf.bptr)) {
if (lfs3_bptr_isbptr(&file->leaf.bptr)
&& lfs3_bptr_off(&file->leaf.bptr)
+ lfs3_bptr_size(&file->leaf.bptr)
< lfs3_bptr_cksize(&file->leaf.bptr)) {
lfs3_bptr_claim(&file->leaf.bptr);
file->b.h.flags &= ~LFS3_o_UNCRYST;
}