From 73eb7856dd711116051abf3d77f97859dc11dc5a Mon Sep 17 00:00:00 2001 From: Gregory Pakosz Date: Tue, 6 Nov 2018 14:56:18 +0100 Subject: [PATCH] enabled and fixed -Wshadow and -Wuseless-cast offences --- _gnu-make/Makefile | 4 ++-- src/whereami.c | 24 +++++++++++------------- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/_gnu-make/Makefile b/_gnu-make/Makefile index cf5954b..2167a3e 100644 --- a/_gnu-make/Makefile +++ b/_gnu-make/Makefile @@ -45,8 +45,8 @@ buildir := $(realpath .)/build binsubdir := $(platform)-$(architecture) bindir := $(prefix)/bin/$(binsubdir) -CFLAGS := -O2 -g -Wall -pedantic -Werror -std=c99 -CXXFLAGS := -O2 -g -Wall -pedantic -Werror +CFLAGS := -O2 -g -Wall -pedantic -Werror -Wshadow -std=c99 +CXXFLAGS := -O2 -g -Wall -pedantic -Werror -Wshadow -Wuseless-cast ifeq ($(platform),linux) LDFLAGS += -ldl diff --git a/src/whereami.c b/src/whereami.c index 6ebd5a2..ff2524c 100644 --- a/src/whereami.c +++ b/src/whereami.c @@ -129,15 +129,13 @@ static int WAI_PREFIX(getModulePath_)(HMODULE module, char* out, int capacity, i return length; } -WAI_NOINLINE -WAI_FUNCSPEC +WAI_NOINLINE WAI_FUNCSPEC int WAI_PREFIX(getExecutablePath)(char* out, int capacity, int* dirname_length) { return WAI_PREFIX(getModulePath_)(NULL, out, capacity, dirname_length); } -WAI_NOINLINE -WAI_FUNCSPEC +WAI_NOINLINE WAI_FUNCSPEC int WAI_PREFIX(getModulePath)(char* out, int capacity, int* dirname_length) { HMODULE module; @@ -238,15 +236,13 @@ int WAI_PREFIX(getExecutablePath)(char* out, int capacity, int* dirname_length) #include #endif -WAI_NOINLINE -WAI_FUNCSPEC +WAI_NOINLINE WAI_FUNCSPEC int WAI_PREFIX(getModulePath)(char* out, int capacity, int* dirname_length) { int length = -1; FILE* maps = NULL; - int i; - for (i = 0; i < WAI_PROC_SELF_MAPS_RETRY; ++i) + for (int r = 0; r < WAI_PROC_SELF_MAPS_RETRY; ++r) { maps = fopen(WAI_PROC_SELF_MAPS, "r"); if (!maps) @@ -267,7 +263,7 @@ int WAI_PREFIX(getModulePath)(char* out, int capacity, int* dirname_length) if (sscanf(buffer, "%" PRIx64 "-%" PRIx64 " %s %" PRIx64 " %x:%x %u %s\n", &low, &high, perms, &offset, &major, &minor, &inode, path) == 8) { - uint64_t addr = (uint64_t)(uintptr_t)WAI_RETURN_ADDRESS(); + uint64_t addr = (uintptr_t)WAI_RETURN_ADDRESS(); if (low <= addr && addr <= high) { char* resolved; @@ -339,11 +335,15 @@ int WAI_PREFIX(getModulePath)(char* out, int capacity, int* dirname_length) } fclose(maps); + maps = NULL; if (length != -1) break; } + if (maps) + fclose(maps); + return length; } @@ -408,8 +408,7 @@ int WAI_PREFIX(getExecutablePath)(char* out, int capacity, int* dirname_length) return length; } -WAI_NOINLINE -WAI_FUNCSPEC +WAI_NOINLINE WAI_FUNCSPEC int WAI_PREFIX(getModulePath)(char* out, int capacity, int* dirname_length) { char buffer[PATH_MAX]; @@ -619,8 +618,7 @@ int WAI_PREFIX(getExecutablePath)(char* out, int capacity, int* dirname_length) return length; } -WAI_NOINLINE -WAI_FUNCSPEC +WAI_NOINLINE WAI_FUNCSPEC int WAI_PREFIX(getModulePath)(char* out, int capacity, int* dirname_length) { char buffer[PATH_MAX];