Commit abe236757933f84fa1485fd56ba99b2e2e8cab65

Edward Thomson 2019-01-17T20:09:05

Merge pull request #4925 from lhchavez/fix-a-bunch-of-warnings Fix a bunch of warnings

diff --git a/deps/zlib/CMakeLists.txt b/deps/zlib/CMakeLists.txt
index b0cb7f7..afa5a19 100644
--- a/deps/zlib/CMakeLists.txt
+++ b/deps/zlib/CMakeLists.txt
@@ -1,3 +1,4 @@
+DISABLE_WARNINGS(implicit-fallthrough)
 ADD_DEFINITIONS(-DNO_VIZ -DSTDC -DNO_GZIP)
 FILE(GLOB SRC_ZLIB "*.c" "*.h")
 INCLUDE_DIRECTORIES(".")
diff --git a/src/cc-compat.h b/src/cc-compat.h
index 0f05cd2..8aaa8bb 100644
--- a/src/cc-compat.h
+++ b/src/cc-compat.h
@@ -47,12 +47,24 @@
 
 /* Define the printf format specifer to use for size_t output */
 #if defined(_MSC_VER) || defined(__MINGW32__)
-#	define PRIuZ "Iu"
-#	define PRIxZ "Ix"
-#	define PRIdZ "Id"
+
+/* The first block is needed to avoid warnings on MingW amd64 */
+#	if (SIZE_MAX == ULLONG_MAX)
+#		define PRIuZ "I64u"
+#		define PRIxZ "I64x"
+#		define PRIXZ "I64X"
+#		define PRIdZ "I64d"
+#	else
+#		define PRIuZ "Iu"
+#		define PRIxZ "Ix"
+#		define PRIXZ "IX"
+#		define PRIdZ "Id"
+#	endif
+
 #else
 #	define PRIuZ "zu"
 #	define PRIxZ "zx"
+#	define PRIXZ "zX"
 #	define PRIdZ "zd"
 #endif
 
diff --git a/src/odb.c b/src/odb.c
index 3aedd80..9bd5d24 100644
--- a/src/odb.c
+++ b/src/odb.c
@@ -95,7 +95,7 @@ int git_odb__format_object_header(
 	int hdr_max = (hdr_size > INT_MAX-2) ? (INT_MAX-2) : (int)hdr_size;
 	int len;
 
-	len = p_snprintf(hdr, hdr_max, "%s %lld", type_str, (long long)obj_len);
+	len = p_snprintf(hdr, hdr_max, "%s %"PRId64, type_str, (int64_t)obj_len);
 
 	if (len < 0 || len >= hdr_max) {
 		giterr_set(GITERR_OS, "object header creation failed");
diff --git a/src/streams/socket.c b/src/streams/socket.c
index 732b459..998e2fe 100644
--- a/src/streams/socket.c
+++ b/src/streams/socket.c
@@ -38,7 +38,7 @@ static void net_set_error(const char *str)
 		giterr_set(GITERR_NET, "%s: %s", str, win32_error);
 		git__free(win32_error);
 	} else {
-		giterr_set(GITERR_NET, str);
+		giterr_set(GITERR_NET, "%s", str);
 	}
 }
 #else
diff --git a/src/transports/winhttp.c b/src/transports/winhttp.c
index 30e2ecb..11b4298 100644
--- a/src/transports/winhttp.c
+++ b/src/transports/winhttp.c
@@ -329,34 +329,6 @@ static void winhttp_stream_close(winhttp_stream *s)
 	s->sent_request = 0;
 }
 
-/**
- * Extract the url and password from a URL. The outputs are pointers
- * into the input.
- */
-static int userpass_from_url(wchar_t **user, int *user_len,
-			     wchar_t **pass, int *pass_len,
-			     const wchar_t *url, int url_len)
-{
-	URL_COMPONENTS components = { 0 };
-
-	components.dwStructSize = sizeof(components);
-	/* These tell WinHttpCrackUrl that we're interested in the fields */
-	components.dwUserNameLength = 1;
-	components.dwPasswordLength = 1;
-
-	if (!WinHttpCrackUrl(url, url_len, 0, &components)) {
-		giterr_set(GITERR_OS, "failed to extract user/pass from url");
-		return -1;
-	}
-
-	*user     = components.lpszUserName;
-	*user_len = components.dwUserNameLength;
-	*pass     = components.lpszPassword;
-	*pass_len = components.dwPasswordLength;
-
-	return 0;
-}
-
 #define SCHEME_HTTP  "http://"
 #define SCHEME_HTTPS "https://"
 
@@ -659,7 +631,7 @@ static int write_chunk(HINTERNET request, const char *buffer, size_t len)
 	git_buf buf = GIT_BUF_INIT;
 
 	/* Chunk header */
-	git_buf_printf(&buf, "%X\r\n", len);
+	git_buf_printf(&buf, "%"PRIXZ"\r\n", len);
 
 	if (git_buf_oom(&buf))
 		return -1;
@@ -747,7 +719,7 @@ static void CALLBACK winhttp_status(
 	else if ((status & WINHTTP_CALLBACK_STATUS_FLAG_SECURITY_CHANNEL_ERROR))
 		giterr_set(GITERR_NET, "security libraries could not be loaded");
 	else
-		giterr_set(GITERR_NET, "unknown security error %d", status);
+		giterr_set(GITERR_NET, "unknown security error %lu", status);
 }
 
 static int winhttp_connect(
@@ -870,7 +842,7 @@ static int do_send_request(winhttp_stream *s, size_t len, int ignore_length)
 				len, 0);
 		}
 
-		if (success || GetLastError() != SEC_E_BUFFER_TOO_SMALL)
+		if (success || GetLastError() != (DWORD)SEC_E_BUFFER_TOO_SMALL)
 			break;
 	}
 
@@ -1170,7 +1142,7 @@ replay:
 		}
 
 		if (HTTP_STATUS_OK != status_code) {
-			giterr_set(GITERR_NET, "request failed with status code: %d", status_code);
+			giterr_set(GITERR_NET, "request failed with status code: %lu", status_code);
 			return -1;
 		}
 
diff --git a/src/win32/posix_w32.c b/src/win32/posix_w32.c
index 5d14493..aa9e618 100644
--- a/src/win32/posix_w32.c
+++ b/src/win32/posix_w32.c
@@ -397,7 +397,6 @@ int p_readlink(const char *path, char *buf, size_t bufsiz)
 int p_symlink(const char *target, const char *path)
 {
 	git_win32_path target_w, path_w;
-	wchar_t *target_p;
 
 	if (git_win32_path_from_utf8(path_w, path) < 0 ||
 		git__utf8_to_16(target_w, MAX_PATH, target) < 0)
diff --git a/tests/clar_libgit2.h b/tests/clar_libgit2.h
index 618aed0..8a0ff4f 100644
--- a/tests/clar_libgit2.h
+++ b/tests/clar_libgit2.h
@@ -40,7 +40,7 @@
 #define cl_win32_pass(expr) do { \
 	int _win32_res; \
 	if ((_win32_res = (expr)) == 0) { \
-		giterr_set(GITERR_OS, "Returned: %d, system error code: %d", _win32_res, GetLastError()); \
+		giterr_set(GITERR_OS, "Returned: %d, system error code: %lu", _win32_res, GetLastError()); \
 		cl_git_report_failure(_win32_res, 0, __FILE__, __LINE__, "System call failed: " #expr); \
 	} \
 	} while(0)
diff --git a/tests/core/vector.c b/tests/core/vector.c
index 2be7e86..a7e1a03 100644
--- a/tests/core/vector.c
+++ b/tests/core/vector.c
@@ -1,3 +1,5 @@
+#include <stdint.h>
+
 #include "clar_libgit2.h"
 #include "vector.h"
 
@@ -66,14 +68,14 @@ void test_core_vector__2(void)
 
 static int compare_them(const void *a, const void *b)
 {
-	return (int)((long)a - (long)b);
+	return (int)((intptr_t)a - (intptr_t)b);
 }
 
 /* insert_sorted */
 void test_core_vector__3(void)
 {
 	git_vector x;
-	long i;
+	intptr_t i;
 	git_vector_init(&x, 1, &compare_them);
 
 	for (i = 0; i < 10; i += 2) {
@@ -96,7 +98,7 @@ void test_core_vector__3(void)
 void test_core_vector__4(void)
 {
 	git_vector x;
-	long i;
+	intptr_t i;
 	git_vector_init(&x, 1, &compare_them);
 
 	for (i = 0; i < 10; i += 2) {
diff --git a/tests/index/addall.c b/tests/index/addall.c
index 49e5079..992cd87 100644
--- a/tests/index/addall.c
+++ b/tests/index/addall.c
@@ -123,8 +123,8 @@ static void check_stat_data(git_index *index, const char *path, bool match)
 		cl_assert(st.st_ctime == entry->ctime.seconds);
 		cl_assert(st.st_mtime == entry->mtime.seconds);
 		cl_assert(st.st_size == entry->file_size);
-		cl_assert(st.st_uid  == entry->uid);
-		cl_assert(st.st_gid  == entry->gid);
+		cl_assert((uint32_t)st.st_uid  == entry->uid);
+		cl_assert((uint32_t)st.st_gid  == entry->gid);
 		cl_assert_equal_i_fmt(
 			GIT_MODE_TYPE(st.st_mode), GIT_MODE_TYPE(entry->mode), "%07o");
 		if (cl_is_chmod_supported())
diff --git a/tests/path/win32.c b/tests/path/win32.c
index f45bf58..3ed7d7a 100644
--- a/tests/path/win32.c
+++ b/tests/path/win32.c
@@ -150,7 +150,7 @@ static void test_remove_namespace(const wchar_t *in, const wchar_t *expected)
 	cl_assert(wcslen(in) < MAX_PATH);
 	wcscpy(canonical, in);
 
-	cl_must_pass(git_win32_path_remove_namespace(canonical, wcslen(in)));
+	git_win32_path_remove_namespace(canonical, wcslen(in));
 	cl_assert_equal_wcs(expected, canonical);
 #else
 	GIT_UNUSED(in);
diff --git a/tests/revwalk/basic.c b/tests/revwalk/basic.c
index 2eb0c35..8e73025 100644
--- a/tests/revwalk/basic.c
+++ b/tests/revwalk/basic.c
@@ -512,7 +512,7 @@ void test_revwalk_basic__big_timestamp(void)
 	cl_git_pass(git_reference_peel((git_object **) &tip, head, GIT_OBJECT_COMMIT));
 
 	/* Commit with a far-ahead timestamp, we should be able to parse it in the revwalk */
-	cl_git_pass(git_signature_new(&sig, "Joe", "joe@example.com", 2399662595, 0));
+	cl_git_pass(git_signature_new(&sig, "Joe", "joe@example.com", 2399662595ll, 0));
 	cl_git_pass(git_commit_tree(&tree, tip));
 
 	cl_git_pass(git_commit_create(&id, _repo, "HEAD", sig, sig, NULL, "some message", tree, 1,