From fa06ce517505b908e59810fdf74f534431800c70 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Tue, 31 Mar 2015 16:49:01 +0100 Subject: [PATCH 1/6] TEMP: turn all warnings into errors Signed-off-by: Johannes Schindelin --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 9999a09490..411669e8bf 100644 --- a/Makefile +++ b/Makefile @@ -355,7 +355,7 @@ GIT-VERSION-FILE: FORCE # CFLAGS and LDFLAGS are for the users to override from the command line. -CFLAGS = -g -O2 -Wall +CFLAGS = -g -O2 -Wall -Werror LDFLAGS = ALL_CFLAGS = $(CPPFLAGS) $(CFLAGS) ALL_LDFLAGS = $(LDFLAGS) From 5e2a65494c2a69d51c98cb59dd99a85c679ee91e Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Tue, 31 Mar 2015 16:00:36 +0100 Subject: [PATCH 2/6] squash! Start supporting MSys2 in config.mak.uname With __USE_MINGW_ANSI_STDIO defined to 0, the printf/scanf formats magically stop throwing warnings! Assisted-by: Waldek Maleska Signed-off-by: Johannes Schindelin --- config.mak.uname | 1 + 1 file changed, 1 insertion(+) diff --git a/config.mak.uname b/config.mak.uname index 06c47af02b..98aad70555 100644 --- a/config.mak.uname +++ b/config.mak.uname @@ -547,6 +547,7 @@ else BASIC_LDFLAGS += -Wl,--large-address-aware endif CC = gcc + COMPAT_CFLAGS += -D__USE_MINGW_ANSI_STDIO=0 INSTALL = /bin/install NO_R_TO_GCC_LINKER = YesPlease INTERNAL_QSORT = YesPlease From c210b6a5fe839f6b458bbf9dfaaaabb36ee483ec Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Tue, 31 Mar 2015 17:14:55 +0100 Subject: [PATCH 3/6] Squelch warning about an integer overflow We cannot rely on long integers to have more than 32 bits... Signed-off-by: Johannes Schindelin --- git-compat-util.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git-compat-util.h b/git-compat-util.h index 6373d93679..fc66006b76 100644 --- a/git-compat-util.h +++ b/git-compat-util.h @@ -516,7 +516,7 @@ extern int git_lstat(const char *, struct stat *); #endif #define DEFAULT_PACKED_GIT_LIMIT \ - ((1024L * 1024L) * (sizeof(void*) >= 8 ? 8192 : 256)) + ((1024L * 1024L) * (size_t)(sizeof(void*) >= 8 ? 8192 : 256)) #ifdef NO_PREAD #define pread git_pread From c557dee8dac08e4fefd11722b6fb98016827a087 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Tue, 31 Mar 2015 17:39:54 +0100 Subject: [PATCH 4/6] mingw: uglify pthread_mutex_init definition to shut up warning When the result of a (a, 0) expression is not used, GCC now finds it necessary to complain with a warning: right-hand operand of comma expression has no effect Let's just pretend to use the 0 value and have a peaceful and quiet life again. Signed-off-by: Johannes Schindelin --- compat/win32/pthread.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/compat/win32/pthread.h b/compat/win32/pthread.h index 1ade961769..62151d7550 100644 --- a/compat/win32/pthread.h +++ b/compat/win32/pthread.h @@ -18,7 +18,10 @@ */ #define pthread_mutex_t CRITICAL_SECTION -#define pthread_mutex_init(a,b) (InitializeCriticalSection((a)), 0) +static inline int return_0(int i) { + return 0; +} +#define pthread_mutex_init(a,b) return_0((InitializeCriticalSection((a)), 0)) #define pthread_mutex_destroy(a) DeleteCriticalSection((a)) #define pthread_mutex_lock EnterCriticalSection #define pthread_mutex_unlock LeaveCriticalSection From 4646cc29938b264871c7907724d9eefb618e0c46 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Tue, 31 Mar 2015 17:51:57 +0100 Subject: [PATCH 5/6] mingw: avoid warnings when casting HANDLEs to int HANDLE is defined internally as a void *, but in many cases it is actually guaranteed to be a 32-bit integer. In these cases, GCC should not warn about a cast of a pointer to an integer of a different type because we know exactly what we are doing. Signed-off-by: Johannes Schindelin --- compat/mingw.c | 13 ++++++++----- compat/poll/poll.c | 2 +- compat/winansi.c | 3 ++- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/compat/mingw.c b/compat/mingw.c index efe840c1e2..ab2957dec3 100644 --- a/compat/mingw.c +++ b/compat/mingw.c @@ -8,6 +8,8 @@ #undef isatty +#define HCAST(type, handle) ((type)(intptr_t)handle) + static const int delay[] = { 0, 1, 10, 20, 40 }; unsigned int _CRT_fmode = _O_BINARY; @@ -728,13 +730,13 @@ int pipe(int filedes[2]) errno = err_win_to_posix(GetLastError()); return -1; } - filedes[0] = _open_osfhandle((int)h[0], O_NOINHERIT); + filedes[0] = _open_osfhandle(HCAST(int, h[0]), O_NOINHERIT); if (filedes[0] < 0) { CloseHandle(h[0]); CloseHandle(h[1]); return -1; } - filedes[1] = _open_osfhandle((int)h[1], O_NOINHERIT); + filedes[1] = _open_osfhandle(HCAST(int, h[1]), O_NOINHERIT); if (filedes[0] < 0) { close(filedes[0]); CloseHandle(h[1]); @@ -1958,7 +1960,8 @@ void mingw_open_html(const char *unixpath) die("cannot run browser"); printf("Launching default browser to display HTML ...\n"); - r = (int)ShellExecute(NULL, "open", htmlpath, NULL, "\\", SW_SHOWNORMAL); + r = HCAST(int, ShellExecute(NULL, "open", htmlpath, + NULL, "\\", SW_SHOWNORMAL)); FreeLibrary(shell32); /* see the MSDN documentation referring to the result codes here */ if (r <= 32) { @@ -2364,8 +2367,8 @@ int mingw_isatty(int fd) { char buffer[64]; for (i = 0; i < ARRAY_SIZE(is_tty); i++) { - sprintf(buffer, " %ld ", (unsigned long) - GetStdHandle(id[i])); + sprintf(buffer, " %" PRIuMAX " ", + HCAST(uintmax_t, GetStdHandle(id[i]))); is_tty[i] = !!strstr(env, buffer); } } diff --git a/compat/poll/poll.c b/compat/poll/poll.c index db4e03ed79..b10adc780f 100644 --- a/compat/poll/poll.c +++ b/compat/poll/poll.c @@ -76,7 +76,7 @@ #ifdef WIN32_NATIVE -#define IsConsoleHandle(h) (((long) (h) & 3) == 3) +#define IsConsoleHandle(h) (((long) (intptr_t) (h) & 3) == 3) static BOOL IsSocketHandle (HANDLE h) diff --git a/compat/winansi.c b/compat/winansi.c index 71fb0a4f25..23dec64007 100644 --- a/compat/winansi.c +++ b/compat/winansi.c @@ -456,7 +456,8 @@ static HANDLE duplicate_handle(HANDLE hnd) HANDLE hresult, hproc = GetCurrentProcess(); if (!DuplicateHandle(hproc, hnd, hproc, &hresult, 0, TRUE, DUPLICATE_SAME_ACCESS)) - die_lasterr("DuplicateHandle(%li) failed", (long) hnd); + die_lasterr("DuplicateHandle(%li) failed", + (long) (intptr_t) hnd); return hresult; } From 5621f24dce4b1ee4c58a39027a08bb653ae29238 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Tue, 31 Mar 2015 18:07:05 +0100 Subject: [PATCH 6/6] Silence GCC's "cast of pointer to integer of a different size" warning When calculating hashes from pointers, it actually makes sense to cut off the most significant bits. In that case, said warning does not make a whole lot of sense. So let's just work around it. Signed-off-by: Johannes Schindelin --- compat/regex/regcomp.c | 4 ++-- pack-revindex.c | 2 +- sha1_file.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/compat/regex/regcomp.c b/compat/regex/regcomp.c index 06f3088708..d8bde06f1a 100644 --- a/compat/regex/regcomp.c +++ b/compat/regex/regcomp.c @@ -2577,7 +2577,7 @@ parse_dup_op (bin_tree_t *elem, re_string_t *regexp, re_dfa_t *dfa, old_tree = NULL; if (elem->token.type == SUBEXP) - postorder (elem, mark_opt_subexp, (void *) (long) elem->token.opr.idx); + postorder (elem, mark_opt_subexp, (void *) (intptr_t) elem->token.opr.idx); tree = create_tree (dfa, elem, NULL, (end == -1 ? OP_DUP_ASTERISK : OP_ALT)); if (BE (tree == NULL, 0)) @@ -3806,7 +3806,7 @@ create_token_tree (re_dfa_t *dfa, bin_tree_t *left, bin_tree_t *right, static reg_errcode_t mark_opt_subexp (void *extra, bin_tree_t *node) { - int idx = (int) (long) extra; + int idx = (int) (intptr_t) extra; if (node->token.type == SUBEXP && node->token.opr.idx == idx) node->token.opt_subexp = 1; diff --git a/pack-revindex.c b/pack-revindex.c index 5c8376e978..e542ea7703 100644 --- a/pack-revindex.c +++ b/pack-revindex.c @@ -21,7 +21,7 @@ static int pack_revindex_hashsz; static int pack_revindex_ix(struct packed_git *p) { - unsigned long ui = (unsigned long)p; + unsigned long ui = (unsigned long)(intptr_t)p; int i; ui = ui ^ (ui >> 16); /* defeat structure alignment */ diff --git a/sha1_file.c b/sha1_file.c index 88f06bac92..77efc0e8a9 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -2017,7 +2017,7 @@ static unsigned long pack_entry_hash(struct packed_git *p, off_t base_offset) { unsigned long hash; - hash = (unsigned long)p + (unsigned long)base_offset; + hash = (unsigned long)(intptr_t)p + (unsigned long)base_offset; hash += (hash >> 8) + (hash >> 16); return hash % MAX_DELTA_CACHE; }