From 160bebaa979fb4e1800523853c21f1083be8e4e7 Mon Sep 17 00:00:00 2001 From: Jason Lee Date: Thu, 30 Nov 2023 14:58:45 -0700 Subject: [PATCH] fix some compiler warnings --- contrib/make_testindex.cpp | 2 +- src/bffuse.c | 10 +++ src/bfresultfuse.c | 10 +++ src/dfw.c | 1 + src/tsmepoch2time.c | 5 ++ src/tsmtime2epoch.c | 6 ++ test/unit/googletest/BottomUp.cpp.in | 81 ++++++++++----------- test/unit/googletest/QueuePerThreadPool.cpp | 15 ++-- test/unit/googletest/template_db.cpp | 14 ++-- 9 files changed, 88 insertions(+), 56 deletions(-) diff --git a/contrib/make_testindex.cpp b/contrib/make_testindex.cpp index 23216be8c..2f0eb59fa 100644 --- a/contrib/make_testindex.cpp +++ b/contrib/make_testindex.cpp @@ -1071,7 +1071,7 @@ int main(int argc, char *argv[]) { clock_gettime(CLOCK_MONOTONIC, &start); // set up progress thread - LoopedThread progress(settings.progress_rate, ThreadArgs::mutex, [&print_mutex, &start, &pool, &settings](){ + LoopedThread progress(settings.progress_rate, ThreadArgs::mutex, [&print_mutex, &start, &settings](){ std::lock_guard print_lock(print_mutex); struct timespec now = {}; diff --git a/src/bffuse.c b/src/bffuse.c index 75ae583bf..81b16debe 100644 --- a/src/bffuse.c +++ b/src/bffuse.c @@ -211,6 +211,9 @@ static int gufir_getattr(const char *path, struct stat *stbuf) { } static int gufir_readdir(const char *path, void *buf, fuse_fill_dir_t filler,off_t offset, struct fuse_file_info *fi) { + (void) offset; + (void) fi; + int rc; sqlite3_stmt *res; const char *tail; @@ -344,6 +347,8 @@ static int gufir_access(const char *path, int mask) { } static int gufir_statfs(const char *path, struct statvfs *stbuf) { + (void) path; + int res; res = statvfs("/", stbuf); @@ -358,6 +363,11 @@ static int gufir_getxattr(const char *path, const char *name, char *value,size_t #else static int gufir_getxattr(const char *path, const char *name, char *value,size_t size) { #endif +#ifdef __APPLE__ + (void) position; +#endif + (void) name; + int rc; sqlite3_stmt *res; const char *tail; diff --git a/src/bfresultfuse.c b/src/bfresultfuse.c index d2f898d95..0ee66b04d 100644 --- a/src/bfresultfuse.c +++ b/src/bfresultfuse.c @@ -221,6 +221,9 @@ static int gufir_getattr(const char *path, struct stat *stbuf) { } static int gufir_readdir(const char *path, void *buf, fuse_fill_dir_t filler,off_t offset, struct fuse_file_info *fi) { + (void) offset; + (void) fi; + size_t i; int rc; sqlite3_stmt *res; @@ -337,6 +340,8 @@ static int gufir_readdir(const char *path, void *buf, fuse_fill_dir_t filler,off } static int gufir_access(const char *path, int mask) { + (void) path; + (void) mask; return 0; } @@ -405,6 +410,11 @@ static int gufir_getxattr(const char *path, const char *name, char *value, size_ static int gufir_getxattr(const char *path, const char *name, char *value, size_t size) #endif { +#ifdef __APPLE__ + (void) position; +#endif + (void) name; + int rc; sqlite3_stmt *res; const char *tail; diff --git a/src/dfw.c b/src/dfw.c index 2547c02eb..b88f121e0 100644 --- a/src/dfw.c +++ b/src/dfw.c @@ -111,6 +111,7 @@ static int printit(const char *name, const struct stat *status, char *type, char static int printload(struct input *in, const char *name, const struct stat *status, char *type, char *linkname, struct xattrs *xattrs, long long pinode, char *sortf, FILE *of) { + (void) pinode; fprintf(of,"%s%c", name,in->delim); fprintf(of,"%c%c", type[0],in->delim); fprintf(of,"%"STAT_ino"%c", status->st_ino,in->delim); diff --git a/src/tsmepoch2time.c b/src/tsmepoch2time.c index a4c4c0bc2..74fae9c54 100644 --- a/src/tsmepoch2time.c +++ b/src/tsmepoch2time.c @@ -4,6 +4,11 @@ int main(int argc, char **argv) { + if (argc < 2) { + fprintf(stderr, "Syntax: %s timestamp", argv[0]); + return 1; + } + struct tm ts; char buf[80]; diff --git a/src/tsmtime2epoch.c b/src/tsmtime2epoch.c index a4c293b43..d6f616998 100644 --- a/src/tsmtime2epoch.c +++ b/src/tsmtime2epoch.c @@ -70,6 +70,11 @@ OF SUCH DAMAGE. int main(int argc, char **argv) { + if (argc < 3) { + fprintf(stderr, "Syntax: %s M/D/Y H/M/S\n", argv[0]); + return 1; + } + struct tm t; time_t t_of_day; int myear; @@ -81,4 +86,5 @@ int main(int argc, char **argv) t_of_day = mktime(&t); printf("seconds since the Epoch: %ld\n", (long) t_of_day); + return 0; } diff --git a/test/unit/googletest/BottomUp.cpp.in b/test/unit/googletest/BottomUp.cpp.in index a4fd51291..c05a95ab5 100644 --- a/test/unit/googletest/BottomUp.cpp.in +++ b/test/unit/googletest/BottomUp.cpp.in @@ -72,6 +72,27 @@ OF SUCH DAMAGE. BU_f f = [](void *args timestamp_sig) -> void { (void) args; }; +/* C Standard 6.10.3/C++ Standard 16.3 Macro replacement */ +static int parallel_bottomup_wrapper(char **root_names, const size_t root_count, + const size_t thread_count, + const size_t user_struct_size, + BU_f descend, BU_f ascend, + const int track_non_dirs, + const int generate_alt_name, + void *extra_args) { + return parallel_bottomup(root_names, root_count, + thread_count, + user_struct_size, + descend, ascend, + track_non_dirs, + generate_alt_name, + extra_args + #if defined(DEBUG) && defined(PER_THREAD_STATS) + , nullptr + #endif + ); +} + TEST(BottomUp, builddir) { const char *roots[] = { "@CMAKE_BINARY_DIR@", @@ -79,42 +100,26 @@ TEST(BottomUp, builddir) { const size_t root_count = sizeof(roots) / sizeof(roots[0]); - EXPECT_EQ(parallel_bottomup((char **) roots, root_count, 1, - sizeof(struct BottomUp), - f, f, 0, 0, nullptr - #if defined(DEBUG) && defined(PER_THREAD_STATS) - , nullptr - #endif - ), 0); + EXPECT_EQ(parallel_bottomup_wrapper((char **) roots, root_count, 1, + sizeof(struct BottomUp), + f, f, 0, 0, nullptr), 0); } TEST(BottomUp, bad) { // bad user struct size - EXPECT_EQ(parallel_bottomup(nullptr, 0, 1, - sizeof(struct BottomUp) - 1, - f, f, 0, 0, nullptr - #if defined(DEBUG) && defined(PER_THREAD_STATS) - , nullptr - #endif - ), -1); + EXPECT_EQ(parallel_bottomup_wrapper(nullptr, 0, 1, + sizeof(struct BottomUp) - 1, + f, f, 0, 0, nullptr), -1); // bad thread count - EXPECT_EQ(parallel_bottomup(nullptr, 0, 0, - sizeof(struct BottomUp), - f, f, 0, 0, nullptr - #if defined(DEBUG) && defined(PER_THREAD_STATS) - , nullptr - #endif - ), -1); + EXPECT_EQ(parallel_bottomup_wrapper(nullptr, 0, 0, + sizeof(struct BottomUp), + f, f, 0, 0, nullptr), -1); /* no root dirs */ - EXPECT_EQ(parallel_bottomup(nullptr, 0, 1, - sizeof(struct BottomUp), - f, f, 0, 0, nullptr - #if defined(DEBUG) && defined(PER_THREAD_STATS) - , nullptr - #endif - ), 0); + EXPECT_EQ(parallel_bottomup_wrapper(nullptr, 0, 1, + sizeof(struct BottomUp), + f, f, 0, 0, nullptr), 0); char badfilename[] = "@CMAKE_BINARY_DIR@/XXXXXX"; int fd = mkstemp(badfilename); @@ -128,22 +133,14 @@ TEST(BottomUp, bad) { const size_t root_count = sizeof(roots) / sizeof(roots[0]); // root path is not directory - EXPECT_EQ(parallel_bottomup(roots, root_count, 1, - sizeof(struct BottomUp), - f, f, 0, 0, nullptr - #if defined(DEBUG) && defined(PER_THREAD_STATS) - , nullptr - #endif - ), 0); + EXPECT_EQ(parallel_bottomup_wrapper(roots, root_count, 1, + sizeof(struct BottomUp), + f, f, 0, 0, nullptr), 0); EXPECT_EQ(remove(badfilename), 0); // root path doesn't exist - EXPECT_EQ(parallel_bottomup(roots, root_count, 1, - sizeof(struct BottomUp), - f, f, 0, 0, nullptr - #if defined(DEBUG) && defined(PER_THREAD_STATS) - , nullptr - #endif - ), 0); + EXPECT_EQ(parallel_bottomup_wrapper(roots, root_count, 1, + sizeof(struct BottomUp), + f, f, 0, 0, nullptr), 0); } diff --git a/test/unit/googletest/QueuePerThreadPool.cpp b/test/unit/googletest/QueuePerThreadPool.cpp index 0e64293d4..d9b99d85b 100644 --- a/test/unit/googletest/QueuePerThreadPool.cpp +++ b/test/unit/googletest/QueuePerThreadPool.cpp @@ -101,13 +101,18 @@ TEST(QueuePerThreadPool, no_start_stop) { QPTPool_destroy(pool); } +/* C Standard 6.10.3/C++ Standard 16.3 Macro replacement */ +static void *qptpool_init_with_props() { + return QPTPool_init_with_props(-1, nullptr, nullptr, nullptr, 0, 0, 0 + #if defined(DEBUG) && defined(PER_THREAD_STATS) + , nullptr + #endif + ); +} + TEST(QueuePreThreadPool, bad_init) { EXPECT_EQ(QPTPool_init(-1, nullptr), nullptr); - EXPECT_EQ(QPTPool_init_with_props(-1, nullptr, nullptr, nullptr, 0, 0, 0 - #if defined(DEBUG) && defined(PER_THREAD_STATS) - , nullptr - #endif - ), nullptr); + EXPECT_EQ(qptpool_init_with_props(), nullptr); } TEST(QueuePerThreadPool, bad_start) { diff --git a/test/unit/googletest/template_db.cpp b/test/unit/googletest/template_db.cpp index 24244bb0f..8f55ba93b 100644 --- a/test/unit/googletest/template_db.cpp +++ b/test/unit/googletest/template_db.cpp @@ -159,10 +159,9 @@ TEST(create_empty_dbdb, good) { char dirname[] = "XXXXXX" ; ASSERT_NE(mkdtemp(dirname), nullptr); - refstr_t dst = { - .data = dirname, - .len = strlen(dirname), - }; + refstr_t dst; + dst.data = dirname; + dst.len = strlen(dirname); // /db.db char dbname[MAXPATH]; @@ -221,10 +220,9 @@ TEST(create_empty_dbdb, path_is_file) { ASSERT_GT(fd, -1); EXPECT_EQ(close(fd), 0); - refstr_t dst = { - .data = filename, - .len = strlen(filename), - }; + refstr_t dst; + dst.data = filename; + dst.len = strlen(filename); // attempt to create file under file EXPECT_EQ(create_empty_dbdb(nullptr, &dst, -1, -1), -1);