diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 665894ee..e35c024e 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 diff --git a/Makefile b/Makefile index e6a43ecb..68a639b4 100644 --- a/Makefile +++ b/Makefile @@ -41,8 +41,7 @@ override CFLAGS += -DLFS2_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 diff --git a/README.md b/README.md index 77718a3b..111d8353 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/ diff --git a/bd/lfs2_filebd.c b/bd/lfs2_filebd.c index c240aa77..84686648 100644 --- a/bd/lfs2_filebd.c +++ b/bd/lfs2_filebd.c @@ -204,7 +204,7 @@ int lfs2_filebd_sync(const struct lfs2_config *cfg) { // file sync lfs2_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 diff --git a/lfs2.c b/lfs2.c index b708196d..7d68b415 100644 --- a/lfs2.c +++ b/lfs2.c @@ -865,11 +865,6 @@ static int lfs2_dir_traverse(lfs2_t *lfs2, }; sp += 1; - dir = dir; - off = off; - ptag = ptag; - attrs = attrs; - attrcount = attrcount; tmask = 0; ttag = 0; begin = 0; @@ -1162,6 +1157,7 @@ static lfs2_stag_t lfs2_dir_fetchmatch(lfs2_t *lfs2, dir->erased = false; break; } + return err; } lfs2_pair_fromle32(temptail); } @@ -2998,12 +2994,14 @@ cleanup: return err; } +#ifndef LFS2_NO_MALLOC static int lfs2_file_rawopen(lfs2_t *lfs2, lfs2_file_t *file, const char *path, int flags) { static const struct lfs2_file_config defaults = {0}; int err = lfs2_file_rawopencfg(lfs2, file, path, flags, &defaults); return err; } +#endif static int lfs2_file_rawclose(lfs2_t *lfs2, lfs2_file_t *file) { #ifndef LFS2_READONLY @@ -4195,7 +4193,7 @@ static int lfs2_rawmount(lfs2_t *lfs2, const struct lfs2_config *cfg) { if (superblock.block_size != lfs2->cfg->block_size) { LFS2_ERROR("Invalid block size (%"PRIu32" != %"PRIu32")", - superblock.block_count, lfs2->cfg->block_count); + superblock.block_size, lfs2->cfg->block_size); err = LFS2_ERR_INVAL; goto cleanup; } diff --git a/lfs2.h b/lfs2.h index 715764f7..161f0ef2 100644 --- a/lfs2.h +++ b/lfs2.h @@ -534,8 +534,8 @@ int lfs2_file_open(lfs2_t *lfs2, lfs2_file_t *file, // are values from the enum lfs2_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 lfs2_file_opencfg(lfs2_t *lfs2, lfs2_file_t *file, diff --git a/lfs2_util.h b/lfs2_util.h index 6a4c8ffb..dd2cbcc1 100644 --- a/lfs2_util.h +++ b/lfs2_util.h @@ -167,10 +167,9 @@ static inline int lfs2_scmp(uint32_t a, uint32_t b) { // Convert between 32-bit little-endian and native order static inline uint32_t lfs2_fromle32(uint32_t a) { -#if !defined(LFS2_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(LFS2_NO_INTRINSICS) && ( \ (defined( BYTE_ORDER ) && defined( ORDER_BIG_ENDIAN ) && BYTE_ORDER == ORDER_BIG_ENDIAN ) || \ @@ -196,10 +195,9 @@ static inline uint32_t lfs2_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(LFS2_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) | diff --git a/scripts/test.py b/scripts/test.py index e8883af8..0191250c 100755 --- a/scripts/test.py +++ b/scripts/test.py @@ -93,7 +93,7 @@ PROLOGUE = """ __attribute__((unused)) lfs2_dir_t dir; __attribute__((unused)) struct lfs2_info info; __attribute__((unused)) char path[1024]; - __attribute__((unused)) uint8_t buffer[1024]; + __attribute__((unused)) uint8_t buffer[(1024 > LFS2_BLOCK_SIZE * 4) ? (1024) : (LFS2_BLOCK_SIZE * 4)]; __attribute__((unused)) lfs2_size_t size; __attribute__((unused)) int err;