From 3ce59930a4a0232a328a43dfc9e40800065257bc Mon Sep 17 00:00:00 2001 From: Yuxuan Shui Date: Wed, 22 Aug 2018 14:25:40 +0100 Subject: [PATCH] More compiler warning flags --- Makefile | 24 +++++++++++++----------- src/common.h | 5 +++-- src/config.c | 2 +- src/opengl.c | 9 +++++++-- 4 files changed, 24 insertions(+), 16 deletions(-) diff --git a/Makefile b/Makefile index 1cc29c6f..9c6178e0 100644 --- a/Makefile +++ b/Makefile @@ -16,7 +16,11 @@ INCS = OBJS = compton.o config.o # === Configuration flags === -CFG = -std=c11 -D_GNU_SOURCE +CFG = -std=c11 -D_GNU_SOURCE -Wall -Wextra -Wno-unused-parameter + +ifeq "$(CC)" "clang" + CFG += -Wconditional-uninitialized +endif # ==== Xinerama ==== # Enables support for --xinerama-shadow-crop @@ -112,24 +116,22 @@ LDFLAGS ?= -Wl,-O1 -Wl,--as-needed BUILD_TYPE ?= "Debug" ifeq "$(BUILD_TYPE)" "Release" - CFLAGS += -DNDEBUG -O2 -D_FORTIFY_SOURCE=2 + CFG += -DNDEBUG -O2 -D_FORTIFY_SOURCE=2 else ifeq "$(BUILD_TYPE)" "Debug" - CFLAGS += -ggdb -Wshadow + CFG += -ggdb -Wshadow endif ifeq "$(ENABLE_SAN)" "1" - CFLAGS += -fsanitize=address,undefined + CFG += -fsanitize=address,undefined else ifeq "$(ENABLE_SAN)" "thread" - CFLAGS += -fsanitize=thread + CFG += -fsanitize=thread else ifeq "$(ENABLE_SAN)" "memory" - CFLAGS += -fsanitize=memory + CFG += -fsanitize=memory endif LIBS += $(shell pkg-config --libs $(PACKAGES)) INCS += $(shell pkg-config --cflags $(PACKAGES)) -CFLAGS += -Wall -Wimplicit-fallthrough - BINS = compton bin/compton-trans MANPAGES = man/compton.1 man/compton-trans.1 MANPAGES_HTML = $(addsuffix .html,$(MANPAGES)) @@ -138,7 +140,7 @@ MANPAGES_HTML = $(addsuffix .html,$(MANPAGES)) .DEFAULT_GOAL := compton src/.clang_complete: Makefile - @(for i in $(filter-out -O% -DNDEBUG, $(CFG) $(CPPFLAGS) $(CFLAGS) $(INCS)); do echo "$$i"; done) > $@ + @(for i in $(filter-out -O% -DNDEBUG, $(CFG) $(CPPFLAGS) $(INCS)); do echo "$$i"; done) > $@ .deps: mkdir -p .deps @@ -149,10 +151,10 @@ src/.clang_complete: Makefile $(CC) -M $(CPPFLAGS) $< > $@.$$$$; \ sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $(DEP); \ rm -f $@.$$$$ - $(CC) $(CFG) $(CPPFLAGS) $(CFLAGS) $(INCS) -c src/$*.c + $(CC) $(CFG) $(CPPFLAGS) $(INCS) -c src/$*.c compton: $(OBJS) - $(CC) $(CFG) $(CPPFLAGS) $(LDFLAGS) $(CFLAGS) -o $@ $(OBJS) $(LIBS) + $(CC) $(CFG) $(CPPFLAGS) $(LDFLAGS) -o $@ $(OBJS) $(LIBS) man/%.1: man/%.1.asciidoc a2x --format manpage $< diff --git a/src/common.h b/src/common.h index 2179b921..f3c6d44f 100644 --- a/src/common.h +++ b/src/common.h @@ -2014,8 +2014,9 @@ rect_crop(XRectangle *pdst, const XRectangle *psrc, const XRectangle *pbound) { */ static inline bool rect_is_fullscreen(session_t *ps, int x, int y, unsigned wid, unsigned hei) { - return (x <= 0 && y <= 0 - && (x + wid) >= ps->root_width && (y + hei) >= ps->root_height); + return (x <= 0 && y <= 0 && + (x + wid) >= (unsigned int)ps->root_width && + (y + hei) >= (unsigned int)ps->root_height); } /** diff --git a/src/config.c b/src/config.c index 1611404e..8c1a3cb2 100644 --- a/src/config.c +++ b/src/config.c @@ -170,7 +170,7 @@ parse_conv_kern_lst(session_t *ps, const char *src, XFixed **dest, int max) { { "9x9gaussian", "9,9,0.000000,0.000000,0.000001,0.000006,0.000012,0.000006,0.000001,0.000000,0.000000,0.000000,0.000003,0.000102,0.000849,0.001723,0.000849,0.000102,0.000003,0.000000,0.000001,0.000102,0.003493,0.029143,0.059106,0.029143,0.003493,0.000102,0.000001,0.000006,0.000849,0.029143,0.243117,0.493069,0.243117,0.029143,0.000849,0.000006,0.000012,0.001723,0.059106,0.493069,0.493069,0.059106,0.001723,0.000012,0.000006,0.000849,0.029143,0.243117,0.493069,0.243117,0.029143,0.000849,0.000006,0.000001,0.000102,0.003493,0.029143,0.059106,0.029143,0.003493,0.000102,0.000001,0.000000,0.000003,0.000102,0.000849,0.001723,0.000849,0.000102,0.000003,0.000000,0.000000,0.000000,0.000001,0.000006,0.000012,0.000006,0.000001,0.000000,0.000000," }, { "11x11gaussian", "11,11,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000001,0.000006,0.000012,0.000006,0.000001,0.000000,0.000000,0.000000,0.000000,0.000000,0.000003,0.000102,0.000849,0.001723,0.000849,0.000102,0.000003,0.000000,0.000000,0.000000,0.000001,0.000102,0.003493,0.029143,0.059106,0.029143,0.003493,0.000102,0.000001,0.000000,0.000000,0.000006,0.000849,0.029143,0.243117,0.493069,0.243117,0.029143,0.000849,0.000006,0.000000,0.000000,0.000012,0.001723,0.059106,0.493069,0.493069,0.059106,0.001723,0.000012,0.000000,0.000000,0.000006,0.000849,0.029143,0.243117,0.493069,0.243117,0.029143,0.000849,0.000006,0.000000,0.000000,0.000001,0.000102,0.003493,0.029143,0.059106,0.029143,0.003493,0.000102,0.000001,0.000000,0.000000,0.000000,0.000003,0.000102,0.000849,0.001723,0.000849,0.000102,0.000003,0.000000,0.000000,0.000000,0.000000,0.000000,0.000001,0.000006,0.000012,0.000006,0.000001,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000," }, }; - for (int i = 0; + for (unsigned int i = 0; i < sizeof(CONV_KERN_PREDEF) / sizeof(CONV_KERN_PREDEF[0]); ++i) if (!strcmp(CONV_KERN_PREDEF[i].name, src)) return parse_conv_kern_lst(ps, CONV_KERN_PREDEF[i].kern_str, dest, max); diff --git a/src/opengl.c b/src/opengl.c index 700ce9d2..eb4c8ded 100644 --- a/src/opengl.c +++ b/src/opengl.c @@ -451,7 +451,12 @@ glx_init_blur(session_t *ps) { { int wid = XFixedToDouble(kern[0]), hei = XFixedToDouble(kern[1]); int nele = wid * hei - 1; - int len = strlen(FRAG_SHADER_BLUR_PREFIX) + strlen(sampler_type) + strlen(extension) + (strlen(shader_add) + strlen(texture_func) + 42) * nele + strlen(FRAG_SHADER_BLUR_SUFFIX) + strlen(texture_func) + 12 + 1; + unsigned int len = strlen(FRAG_SHADER_BLUR_PREFIX) + + strlen(sampler_type) + + strlen(extension) + + (strlen(shader_add) + strlen(texture_func) + 42) * nele + + strlen(FRAG_SHADER_BLUR_SUFFIX) + + strlen(texture_func) + 12 + 1; char *shader_str = calloc(len, sizeof(char)); if (!shader_str) { printf_errf("(): Failed to allocate %d bytes for shader string.", len); @@ -1899,7 +1904,7 @@ glx_create_program_from_str(const char *vert_shader_str, { GLuint shaders[2]; - int count = 0; + unsigned int count = 0; if (vert_shader) shaders[count++] = vert_shader; if (frag_shader)