From 92fc780f7122de409b0d734c519f28e1d81f0fa4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20de=20Giessen?= Date: Mon, 23 Oct 2023 13:35:34 +0200 Subject: [PATCH 1/2] lfs_fs_raw* functions should be static --- lfs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lfs.c b/lfs.c index 0827331..aed1b07 100644 --- a/lfs.c +++ b/lfs.c @@ -4999,7 +4999,7 @@ static int lfs_fs_forceconsistency(lfs_t *lfs) { #endif #ifndef LFS_READONLY -int lfs_fs_rawmkconsistent(lfs_t *lfs) { +static int lfs_fs_rawmkconsistent(lfs_t *lfs) { // lfs_fs_forceconsistency does most of the work here int err = lfs_fs_forceconsistency(lfs); if (err) { @@ -5046,7 +5046,7 @@ static lfs_ssize_t lfs_fs_rawsize(lfs_t *lfs) { } #ifndef LFS_READONLY -int lfs_fs_rawgrow(lfs_t *lfs, lfs_size_t block_count) { +static int lfs_fs_rawgrow(lfs_t *lfs, lfs_size_t block_count) { // shrinking is not supported LFS_ASSERT(block_count >= lfs->block_count); From 8f3f32d1f31e9b233a22eafa04257b5c9a073160 Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Tue, 24 Oct 2023 11:58:44 -0500 Subject: [PATCH 2/2] Added -Wmissing-prototypes This warning is useful for catching the easy mistake of missing the keyword static on functions intended to be internal-only. Missing the static keyword risks symbol polution and misses potential compiler optimizations. This is an interesting warning, while useful for libraries such as littlefs, it's perfectly valid C to not predeclare all functions, and common in final application binaries. Relatedly, this warning is re-disabled for the test/bench runner. There may be a better way to organize the CFLAGS, maybe into separate LIB/RUNNER CFLAGS, but I'll leave this to future work if our CFLAGS grow more complicated. This was motivated by non-static internal-only functions leaking into a release. Found and fixed by DvdGiessen. --- Makefile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Makefile b/Makefile index 24865e5..51e9f98 100644 --- a/Makefile +++ b/Makefile @@ -63,6 +63,7 @@ CFLAGS += -fcallgraph-info=su CFLAGS += -g3 CFLAGS += -I. CFLAGS += -std=c99 -Wall -Wextra -pedantic +CFLAGS += -Wmissing-prototypes CFLAGS += -ftrack-macro-expansion=0 ifdef DEBUG CFLAGS += -O0 @@ -354,6 +355,7 @@ summary-diff sizes-diff: $(OBJ) $(CI) ## Build the test-runner .PHONY: test-runner build-test +test-runner build-test: CFLAGS+=-Wno-missing-prototypes ifndef NO_COV test-runner build-test: CFLAGS+=--coverage endif @@ -405,6 +407,7 @@ testmarks-diff: $(TEST_CSV) ## Build the bench-runner .PHONY: bench-runner build-bench +bench-runner build-bench: CFLAGS+=-Wno-missing-prototypes ifdef YES_COV bench-runner build-bench: CFLAGS+=--coverage endif