From 5832d4aaead5ff85c4303f2b4c0df9f8b0411682 Mon Sep 17 00:00:00 2001 From: Shlomi Fish Date: Fri, 17 Dec 2021 17:01:49 +0200 Subject: [PATCH] Silence compile-time or run-time warnings. See: * https://duckduckgo.com/?q=warnings+programming&atb=v140-1&ia=web They are a distraction at best and may indicate other issues. --- fortune-mod/CMakeLists.txt | 5 +++++ fortune-mod/fortune/fortune.c | 6 +++--- fortune-mod/util/randstr.c | 15 +++++++-------- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/fortune-mod/CMakeLists.txt b/fortune-mod/CMakeLists.txt index 7ebbfca..ed8cbd9 100644 --- a/fortune-mod/CMakeLists.txt +++ b/fortune-mod/CMakeLists.txt @@ -110,6 +110,11 @@ INCLUDE ("${CMAKE_SOURCE_DIR}/cmake/rinutils_bootstrap.cmake") RINUTILS_SET_UP_FLAGS() +IF ("$ENV{FCS_CLANG}") + ADD_DEFINITIONS("-Weverything -Wno-language-extension-token -Wno-padded -Wno-gnu-statement-expression -Wno-unused-parameter -Wno-vla -Wno-cast-align -Wno-used-but-marked-unused -Wno-cast-qual -Wno-comma -Wno-disabled-macro-expansion -Wno-extra-semi-stmt -Wno-documentation-unknown-command -Wno-documentation -Wno-documentation-deprecated-sync -Wno-pass-failed -Wno-implicit-fallthrough") + # ADD_DEFINITIONS("-Weverything") +ENDIF () + IF ($ENV{FCS_GCC}) ADD_DEFINITIONS("-W -Wabi=11 -Waddress -Waggressive-loop-optimizations -Wall -Wattributes -Wbad-function-cast -Wbool-compare -Wbool-operation -Wbuiltin-declaration-mismatch -Wbuiltin-macro-redefined -Wcast-align -Wchar-subscripts -Wclobbered -Wcomment -Wcomments -Wcoverage-mismatch -Wcpp -Wdangling-else -Wdate-time -Wdeprecated -Wdeprecated-declarations -Wdesignated-init -Wdisabled-optimization -Wdiscarded-array-qualifiers -Wdiscarded-qualifiers -Wdiv-by-zero -Wdouble-promotion -Wduplicated-branches -Wduplicated-cond -Wduplicate-decl-specifier -Wempty-body -Wendif-labels -Wenum-compare -Wexpansion-to-defined -Wextra -Wformat-contains-nul -Wformat-extra-args -Wformat-nonliteral -Wformat-security -Wformat-signedness -Wformat-y2k -Wformat-zero-length -Wframe-address -Wfree-nonheap-object -Whsa -Wignored-attributes -Wignored-qualifiers -Wimplicit -Wimplicit-function-declaration -Wimplicit-int -Wincompatible-pointer-types -Winit-self -Winline -Wint-conversion -Wint-in-bool-context -Wint-to-pointer-cast -Winvalid-memory-model -Winvalid-pch -Wjump-misses-init -Wlogical-not-parentheses -Wlogical-op -Wmain -Wmaybe-uninitialized -Wmemset-elt-size -Wmemset-transposed-args -Wmisleading-indentation -Wmissing-braces -Wmissing-declarations -Wmissing-field-initializers -Wmissing-include-dirs -Wmissing-parameter-type -Wmissing-prototypes -Wmultichar -Wnarrowing -Wnested-externs -Wnonnull -Wnonnull-compare -Wnull-dereference -Wodr -Wold-style-declaration -Wold-style-definition -Wopenmp-simd -Woverflow -Woverlength-strings -Woverride-init -Wpacked -Wpacked-bitfield-compat -Wparentheses -Wpointer-arith -Wpointer-compare -Wpointer-sign -Wpointer-to-int-cast -Wpragmas -Wpsabi -Wrestrict -Wreturn-local-addr -Wreturn-type -Wscalar-storage-order -Wsequence-point -Wshadow -Wshift-count-negative -Wshift-count-overflow -Wshift-negative-value -Wsizeof-array-argument -Wsizeof-pointer-memaccess -Wstack-protector -Wstrict-aliasing -Wstrict-prototypes -Wsuggest-attribute=format -Wsuggest-attribute=noreturn -Wsuggest-attribute=pure -Wsuggest-final-methods -Wsuggest-final-types -Wswitch -Wswitch-bool -Wswitch-default -Wswitch-unreachable -Wsync-nand -Wtautological-compare -Wtrampolines -Wtrigraphs -Wtype-limits -Wuninitialized -Wunknown-pragmas -Wunsafe-loop-optimizations -Wunused -Wunused-but-set-parameter -Wunused-but-set-variable -Wunused-function -Wunused-label -Wunused-local-typedefs -Wunused-macros -Wunused-parameter -Wunused-result -Wunused-value -Wunused-variable -Wvarargs -Wvariadic-macros -Wvector-operation-performance -Wvla -Wvolatile-register-var -Wwrite-strings -Walloc-size-larger-than=9223372036854775807 -Warray-bounds=2 -Wformat-overflow=2 -Wformat-truncation=2 -Wnormalized=nfc -Wshift-overflow=2 -Wunused-const-variable=2 -Wstrict-overflow=1 -Wno-switch-default -Wno-vla -Wno-inline -Wno-jump-misses-init -Wno-unsafe-loop-optimizations") # -Wimplicit-fallthrough=5 diff --git a/fortune-mod/fortune/fortune.c b/fortune-mod/fortune/fortune.c index fa75c7d..e9503ad 100644 --- a/fortune-mod/fortune/fortune.c +++ b/fortune-mod/fortune/fortune.c @@ -228,7 +228,7 @@ static unsigned long my_random(const unsigned long base) fclose(fp); return l % base; fallback: - return random() % base; + return (((unsigned long)random()) % base); } static char *program_version(void) @@ -1524,7 +1524,7 @@ static FILEDESC *pick_child(FILEDESC *parent) if (Equal_probs) { - choice = my_random(parent->num_children); + choice = (int)my_random((unsigned long)parent->num_children); DPRINTF(1, (stderr, " choice = %d (of %d)\n", choice, parent->num_children)); for (fp = parent->child; choice--; fp = fp->next) @@ -1600,7 +1600,7 @@ static void get_fort(void) } else { - choice = my_random(100); + choice = (int)my_random(100); DPRINTF(1, (stderr, "choice = %d\n", choice)); for (fp = File_list; fp->percent != NO_PROB; fp = fp->next) { diff --git a/fortune-mod/util/randstr.c b/fortune-mod/util/randstr.c index 83ea92f..15637eb 100644 --- a/fortune-mod/util/randstr.c +++ b/fortune-mod/util/randstr.c @@ -90,7 +90,7 @@ static char *input_filename, data_filename[MAXPATHLEN]; -static FILE *Inf, *Dataf, *Outf; +static FILE *Inf, *Dataf; static off_t pos, Seekpts[2]; /* seek pointers to fortunes */ @@ -139,13 +139,14 @@ static void get_pos(STRFILE *fp) static void get_fort(STRFILE fp) { get_pos(&fp); - fseek(Dataf, (long)(sizeof fp + pos * sizeof Seekpts[0]), SEEK_SET); + fseek(Dataf, (long)((long)sizeof(fp) + pos * (long)sizeof(Seekpts[0])), + SEEK_SET); if (!fread(Seekpts, sizeof Seekpts, 1, Dataf)) { exit(1); } - Seekpts[0] = ntohl(Seekpts[0]); - Seekpts[1] = ntohl(Seekpts[1]); + Seekpts[0] = ntohl((uint32_t)Seekpts[0]); + Seekpts[1] = ntohl((uint32_t)Seekpts[1]); } static void display(FILE *fp, STRFILE table) @@ -206,10 +207,8 @@ int main(int argc GCC_UNUSED, char **argv) get_fort(tbl); display(Inf, tbl); - exit(0); - fclose(Inf); fclose(Dataf); - fclose(Outf); - exit(0); + + return 0; } -- 2.40.0