diff --git a/.travis.yml b/.travis.yml index 0651efc..b6c4f7a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,6 +9,9 @@ script: -include stdio.h -Werror' make all size # run tests - - CFLAGS="-DLFS_READ_SIZE=16 -DLFS_PROG_SIZE=16" make test + - make test + + # run tests with a few different configurations - CFLAGS="-DLFS_READ_SIZE=1 -DLFS_PROG_SIZE=1" make test - CFLAGS="-DLFS_READ_SIZE=512 -DLFS_PROG_SIZE=512" make test + - CFLAGS="-DLFS_BLOCK_COUNT=1023" make test diff --git a/lfs.c b/lfs.c index 463c097..76a1b19 100644 --- a/lfs.c +++ b/lfs.c @@ -262,7 +262,10 @@ int lfs_deorphan(lfs_t *lfs); static int lfs_alloc_lookahead(void *p, lfs_block_t block) { lfs_t *lfs = p; - lfs_block_t off = (block - lfs->free.start) % lfs->cfg->block_count; + lfs_block_t off = (((lfs_soff_t)(block - lfs->free.start) + % (lfs_soff_t)(lfs->cfg->block_count)) + + lfs->cfg->block_count) % lfs->cfg->block_count; + if (off < lfs->cfg->lookahead) { lfs->free.lookahead[off / 32] |= 1U << (off % 32); } @@ -994,6 +997,7 @@ static int lfs_index_extend(lfs_t *lfs, if (err) { return err; } + assert(*block >= 2 && *block <= lfs->cfg->block_count); err = lfs_bd_erase(lfs, *block); if (err) {