From 9899c7fe486d4a581fb84ecf832a574896d411b7 Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Tue, 21 May 2019 17:21:52 -0500 Subject: [PATCH] Fixed read cache amount based on hint and offset Found by apmorton --- lfs.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lfs.c b/lfs.c index 7692d09..b0e6819 100644 --- a/lfs.c +++ b/lfs.c @@ -84,9 +84,12 @@ static int lfs_bd_read(lfs_t *lfs, LFS_ASSERT(block < lfs->cfg->block_count); rcache->block = block; rcache->off = lfs_aligndown(off, lfs->cfg->read_size); - rcache->size = lfs_min(lfs_alignup(off+hint, lfs->cfg->read_size), - lfs_min(lfs->cfg->block_size - rcache->off, - lfs->cfg->cache_size)); + rcache->size = lfs_min( + lfs_min( + lfs_alignup(off+hint, lfs->cfg->read_size), + lfs->cfg->block_size) + - rcache->off, + lfs->cfg->cache_size); int err = lfs->cfg->read(lfs->cfg, rcache->block, rcache->off, rcache->buffer, rcache->size); if (err) {