From 651e14e79683be0cab30b91858018c19159968c1 Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Tue, 9 Apr 2019 18:37:53 -0500 Subject: [PATCH] Cleaned up a couple of warnings - Shifting signed 32-bit value by 31 bits is undefined behaviour This was an interesting one as on initial inspection, `uint8_t & 1` looks like it will result in an unsigned variable. However, due to uint8_t being "smaller" than int, this actually results in a signed int, causing an undefined shift operation. - Identical inner 'if' condition is always true (outer condition is 'true' and inner condition is 'true'). This was caused by the use of `if (true) {` to avoid "goto bypasses variable initialization" warnings. Using just `{` instead seems to avoid this problem. found by keck-in-space and armandas --- lfs.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/lfs.c b/lfs.c index 57a51de..96a7869 100644 --- a/lfs.c +++ b/lfs.c @@ -855,7 +855,7 @@ static lfs_stag_t lfs_dir_fetchmatch(lfs_t *lfs, } // reset the next bit if we need to - ptag ^= (lfs_tag_chunk(tag) & 1) << 31; + ptag ^= (lfs_tag_chunk(tag) & 1U) << 31; // toss our crc into the filesystem seed for // pseudorandom numbers @@ -1498,7 +1498,7 @@ static int lfs_dir_compact(lfs_t *lfs, // begin loop to commit compaction to blocks until a compact sticks while (true) { - if (true) { + { // There's nothing special about our global delta, so feed it into // our local global delta int err = lfs_dir_getgstate(lfs, dir, &lfs->gdelta); @@ -1603,7 +1603,6 @@ static int lfs_dir_compact(lfs_t *lfs, lfs_gstate_xormove(&lfs->gpending, &lfs->gpending, 0x3ff, NULL); } - } break; @@ -2123,7 +2122,7 @@ static int lfs_ctz_extend(lfs_t *lfs, } LFS_ASSERT(nblock >= 2 && nblock <= lfs->cfg->block_count); - if (true) { + { err = lfs_bd_erase(lfs, nblock); if (err) { if (err == LFS_ERR_CORRUPT) { @@ -3298,7 +3297,7 @@ static int lfs_deinit(lfs_t *lfs) { int lfs_format(lfs_t *lfs, const struct lfs_config *cfg) { int err = 0; - if (true) { + { err = lfs_init(lfs, cfg); if (err) { return err; @@ -4182,7 +4181,7 @@ static int lfs1_moved(lfs_t *lfs, const void *e) { static int lfs1_mount(lfs_t *lfs, struct lfs1 *lfs1, const struct lfs_config *cfg) { int err = 0; - if (true) { + { err = lfs_init(lfs, cfg); if (err) { return err; @@ -4253,7 +4252,7 @@ int lfs_migrate(lfs_t *lfs, const struct lfs_config *cfg) { return err; } - if (true) { + { // iterate through each directory, copying over entries // into new directory lfs1_dir_t dir1;