From 6c720dc2bb70317661f842be9da8cc426215c3af Mon Sep 17 00:00:00 2001 From: Kevin ORourke Date: Mon, 25 Apr 2022 12:12:41 +0200 Subject: [PATCH 01/11] Fix unused function warning with LFS_NO_MALLOC --- lfs.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lfs.c b/lfs.c index 117595e..6a56f94 100644 --- a/lfs.c +++ b/lfs.c @@ -2998,12 +2998,14 @@ cleanup: return err; } +#ifndef LFS_NO_MALLOC static int lfs_file_rawopen(lfs_t *lfs, lfs_file_t *file, const char *path, int flags) { static const struct lfs_file_config defaults = {0}; int err = lfs_file_rawopencfg(lfs, file, path, flags, &defaults); return err; } +#endif static int lfs_file_rawclose(lfs_t *lfs, lfs_file_t *file) { #ifndef LFS_READONLY From 9af63b3844434b9c77b1d52af1ab0e2df3be42cc Mon Sep 17 00:00:00 2001 From: Jan Boon Date: Sat, 9 Jul 2022 17:17:25 +0800 Subject: [PATCH 02/11] Fix buffer overflow in tests when using a large block size --- scripts/test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/test.py b/scripts/test.py index 92a13b1..c8196b3 100755 --- a/scripts/test.py +++ b/scripts/test.py @@ -93,7 +93,7 @@ PROLOGUE = """ __attribute__((unused)) lfs_dir_t dir; __attribute__((unused)) struct lfs_info info; __attribute__((unused)) char path[1024]; - __attribute__((unused)) uint8_t buffer[1024]; + __attribute__((unused)) uint8_t buffer[(1024 > LFS_BLOCK_SIZE * 4) ? (1024) : (LFS_BLOCK_SIZE * 4)]; __attribute__((unused)) lfs_size_t size; __attribute__((unused)) int err; From a405c3293fffc255c24aeb9fe08bd42e131bd701 Mon Sep 17 00:00:00 2001 From: Mikhail Paulyshka Date: Wed, 27 Jul 2022 17:06:51 +0300 Subject: [PATCH 03/11] lfs_filebd_sync: fix compilation on Windows --- bd/lfs_filebd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bd/lfs_filebd.c b/bd/lfs_filebd.c index 98e5abc..ee0c31e 100644 --- a/bd/lfs_filebd.c +++ b/bd/lfs_filebd.c @@ -204,7 +204,7 @@ int lfs_filebd_sync(const struct lfs_config *cfg) { // file sync lfs_filebd_t *bd = cfg->context; #ifdef _WIN32 - int err = FlushFileBuffers((HANDLE) _get_osfhandle(fd)) ? 0 : -1; + int err = FlushFileBuffers((HANDLE) _get_osfhandle(bd->fd)) ? 0 : -1; #else int err = fsync(bd->fd); #endif From 23747628d58498fecce108df80b2d4dcbeb9071f Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Wed, 7 Sep 2022 12:23:44 -0500 Subject: [PATCH 04/11] Added clang build step to CI As found by dpgeorge, clang has slightly different warnings than GCC. There's really no cost to running clang as an extra build step to test for these. --- .github/workflows/test.yml | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index bc8bb0c..81f00c1 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -292,6 +292,27 @@ jobs: - name: test-valgrind run: make test TESTFLAGS+="-k --valgrind" + # test that compilation is warning free under clang + clang: + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@v2 + - name: install + run: | + # need toml, also pip3 isn't installed by default? + sudo apt-get update -qq + sudo apt-get install -qq python3 python3-pip + sudo pip3 install toml + - name: install-clang + run: | + sudo apt-get update -qq + sudo apt-get install -qq clang + echo "CC=clang" >> $GITHUB_ENV + clang --version + # no reason to not test again + - name: test-clang + run: make test TESTFLAGS+="-k" + # self-host with littlefs-fuse for a fuzz-like test fuse: runs-on: ubuntu-20.04 From 30175de38414afd6e6e0c77de06649933e535526 Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Wed, 7 Sep 2022 12:38:04 -0500 Subject: [PATCH 05/11] Remove -Wshadow -Wjump-misses-init -Wundef Doing this now specifically because clang does not have -Wjump-misses-init, but I've been looking for an excuse to remove these for a while. These warning flags create more annoyance than they add value. There is probably a reason they aren't included in -Wall + -Wextra. -Wshadow specifically is potentially harmful as it forces coming up with new, sometimes less descriptive names for repeated variables. Dependent projects should use different flags for their dependencies if this introduces problems. --- Makefile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 7cc59f8..1387933 100644 --- a/Makefile +++ b/Makefile @@ -41,8 +41,7 @@ override CFLAGS += -DLFS_YES_TRACE endif override CFLAGS += -g3 override CFLAGS += -I. -override CFLAGS += -std=c99 -Wall -pedantic -override CFLAGS += -Wextra -Wshadow -Wjump-misses-init -Wundef +override CFLAGS += -std=c99 -Wall -Wextra -pedantic ifdef VERBOSE override TESTFLAGS += -v From 47914b925fd8dd558b68dffc826f9a4097519e0e Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Wed, 7 Sep 2022 12:46:29 -0500 Subject: [PATCH 06/11] Fixed self-assign warnings discovered by clang --- lfs.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/lfs.c b/lfs.c index 117595e..9e47bb2 100644 --- a/lfs.c +++ b/lfs.c @@ -865,11 +865,6 @@ static int lfs_dir_traverse(lfs_t *lfs, }; sp += 1; - dir = dir; - off = off; - ptag = ptag; - attrs = attrs; - attrcount = attrcount; tmask = 0; ttag = 0; begin = 0; From a25681b2a6c85bff3fa308c29ba3634b7894c0bd Mon Sep 17 00:00:00 2001 From: Xenoamor Date: Sun, 11 Sep 2022 10:11:23 +0100 Subject: [PATCH 07/11] Improve lfs_file_close usage description Improve the lfs_file_close usage description to make it clearer that the configuration structure must remain valid for its lifetime In reference to #722 --- lfs.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lfs.h b/lfs.h index 3fc1e98..2bce17f 100644 --- a/lfs.h +++ b/lfs.h @@ -534,8 +534,8 @@ int lfs_file_open(lfs_t *lfs, lfs_file_t *file, // are values from the enum lfs_open_flags that are bitwise-ored together. // // The config struct provides additional config options per file as described -// above. The config struct must be allocated while the file is open, and the -// config struct must be zeroed for defaults and backwards compatibility. +// above. The config struct must remain allocated while the file is open, and +// the config struct must be zeroed for defaults and backwards compatibility. // // Returns a negative error code on failure. int lfs_file_opencfg(lfs_t *lfs, lfs_file_t *file, From eb9f4d5d7edeeac07c249c9ea392440c6f6cfb2b Mon Sep 17 00:00:00 2001 From: "Cliff L. Biffle" Date: Sun, 9 Oct 2022 17:45:14 -0700 Subject: [PATCH 08/11] Fix invalid block size reporting. This boilerplate got copied from the stanza just above and incompletely edited. --- lfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lfs.c b/lfs.c index 117595e..d69e950 100644 --- a/lfs.c +++ b/lfs.c @@ -4195,7 +4195,7 @@ static int lfs_rawmount(lfs_t *lfs, const struct lfs_config *cfg) { if (superblock.block_size != lfs->cfg->block_size) { LFS_ERROR("Invalid block size (%"PRIu32" != %"PRIu32")", - superblock.block_count, lfs->cfg->block_count); + superblock.block_size, lfs->cfg->block_size); err = LFS_ERR_INVAL; goto cleanup; } From 9e965a85636a342c84dd805ee5d288c142dc4802 Mon Sep 17 00:00:00 2001 From: Carles Cufi Date: Thu, 27 Oct 2022 11:33:40 +0200 Subject: [PATCH 09/11] lfs_util: Fix endiannes conversion when LFS_NO_INTRINSICS is set The logic for endiannes conversion was wrong when LFS_NO_INTRINSICS was set, since on endinanes match a check of that macro would prevent the unchanged value from being returned. Signed-off-by: Carles Cufi --- lfs_util.h | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/lfs_util.h b/lfs_util.h index 0cbc2a3..13e9396 100644 --- a/lfs_util.h +++ b/lfs_util.h @@ -167,10 +167,9 @@ static inline int lfs_scmp(uint32_t a, uint32_t b) { // Convert between 32-bit little-endian and native order static inline uint32_t lfs_fromle32(uint32_t a) { -#if !defined(LFS_NO_INTRINSICS) && ( \ - (defined( BYTE_ORDER ) && defined( ORDER_LITTLE_ENDIAN ) && BYTE_ORDER == ORDER_LITTLE_ENDIAN ) || \ +#if (defined( BYTE_ORDER ) && defined( ORDER_LITTLE_ENDIAN ) && BYTE_ORDER == ORDER_LITTLE_ENDIAN ) || \ (defined(__BYTE_ORDER ) && defined(__ORDER_LITTLE_ENDIAN ) && __BYTE_ORDER == __ORDER_LITTLE_ENDIAN ) || \ - (defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)) + (defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) return a; #elif !defined(LFS_NO_INTRINSICS) && ( \ (defined( BYTE_ORDER ) && defined( ORDER_BIG_ENDIAN ) && BYTE_ORDER == ORDER_BIG_ENDIAN ) || \ @@ -196,10 +195,9 @@ static inline uint32_t lfs_frombe32(uint32_t a) { (defined(__BYTE_ORDER ) && defined(__ORDER_LITTLE_ENDIAN ) && __BYTE_ORDER == __ORDER_LITTLE_ENDIAN ) || \ (defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)) return __builtin_bswap32(a); -#elif !defined(LFS_NO_INTRINSICS) && ( \ - (defined( BYTE_ORDER ) && defined( ORDER_BIG_ENDIAN ) && BYTE_ORDER == ORDER_BIG_ENDIAN ) || \ +#elif (defined( BYTE_ORDER ) && defined( ORDER_BIG_ENDIAN ) && BYTE_ORDER == ORDER_BIG_ENDIAN ) || \ (defined(__BYTE_ORDER ) && defined(__ORDER_BIG_ENDIAN ) && __BYTE_ORDER == __ORDER_BIG_ENDIAN ) || \ - (defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)) + (defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) return a; #else return (((uint8_t*)&a)[0] << 24) | From d08f949afdeae0af84989330cc571ae91ed10838 Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Fri, 4 Nov 2022 13:43:06 -0500 Subject: [PATCH 10/11] Fixed lfs_dir_fetchmatch not propogating bd errors correctly in one case Found by cbiffle --- lfs.c | 1 + 1 file changed, 1 insertion(+) diff --git a/lfs.c b/lfs.c index 117595e..b8a05b0 100644 --- a/lfs.c +++ b/lfs.c @@ -1162,6 +1162,7 @@ static lfs_stag_t lfs_dir_fetchmatch(lfs_t *lfs, dir->erased = false; break; } + return err; } lfs_pair_fromle32(temptail); } From 740d9ac4ccdd2166e5cbf6df1d53f501df69e498 Mon Sep 17 00:00:00 2001 From: monowii Date: Thu, 21 Apr 2022 15:11:33 +0200 Subject: [PATCH 11/11] Fix readme Mbed link --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 584ada3..32b3793 100644 --- a/README.md +++ b/README.md @@ -252,7 +252,7 @@ License Identifiers that are here available: http://spdx.org/licenses/ [mklfs]: https://github.com/whitecatboard/Lua-RTOS-ESP32/tree/master/components/mklfs/src [Lua RTOS]: https://github.com/whitecatboard/Lua-RTOS-ESP32 [Mbed OS]: https://github.com/armmbed/mbed-os -[LittleFileSystem]: https://os.mbed.com/docs/mbed-os/v5.12/apis/littlefilesystem.html +[LittleFileSystem]: https://os.mbed.com/docs/mbed-os/latest/apis/littlefilesystem.html [SPIFFS]: https://github.com/pellepl/spiffs [Dhara]: https://github.com/dlbeer/dhara [littlefs-python]: https://pypi.org/project/littlefs-python/