Commit 574671ba8e0ca487dead726a4addd9841fa4e6fa

Edward Thomson 2018-02-18T10:16:15

Merge pull request #4534 from pks-t/pks/build-warnings Fix build warnings

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 53f10ba..2e98bbc 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -218,7 +218,7 @@ ELSE ()
 
 	ENABLE_WARNINGS(documentation)
 	DISABLE_WARNINGS(missing-field-initializers)
-	ENABLE_WARNINGS(strict-aliasing=2)
+	ENABLE_WARNINGS(strict-aliasing)
 	ENABLE_WARNINGS(strict-prototypes)
 	ENABLE_WARNINGS(declaration-after-statement)
 	DISABLE_WARNINGS(unused-const-variable)
diff --git a/src/index.c b/src/index.c
index b7602fb..d782a08 100644
--- a/src/index.c
+++ b/src/index.c
@@ -2494,7 +2494,7 @@ static int parse_index(git_index *index, const char *buffer, size_t buffer_size)
 
 	/* Parse all the entries */
 	for (i = 0; i < header.entry_count && buffer_size > INDEX_FOOTER_SIZE; ++i) {
-		git_index_entry *entry;
+		git_index_entry *entry = NULL;
 		size_t entry_size = read_entry(&entry, index, buffer, buffer_size, last);
 
 		/* 0 bytes read means an object corruption */
diff --git a/src/patch_parse.c b/src/patch_parse.c
index 27c01e9..acdd45e 100644
--- a/src/patch_parse.c
+++ b/src/patch_parse.c
@@ -575,6 +575,7 @@ static int parse_hunk_body(
 		switch (c) {
 		case '\n':
 			prefix = 0;
+			/* fall through */
 
 		case ' ':
 			origin = GIT_DIFF_LINE_CONTEXT;
diff --git a/src/revparse.c b/src/revparse.c
index 4ab4fb9..7cb22f4 100644
--- a/src/revparse.c
+++ b/src/revparse.c
@@ -770,7 +770,6 @@ int revparse__ext(
 		}
 
 		case '@':
-		{
 			if (spec[pos+1] == '{') {
 				git_object *temp_object = NULL;
 
@@ -786,10 +785,8 @@ int revparse__ext(
 				if (temp_object != NULL)
 					base_rev = temp_object;
 				break;
-			} else {
-				/* Fall through */
 			}
-		}
+			/* fall through */
 
 		default:
 			if ((error = ensure_left_hand_identifier_is_not_known_yet(base_rev, reference)) < 0)
diff --git a/src/streams/openssl.c b/src/streams/openssl.c
index d00e98e..9cbb274 100644
--- a/src/streams/openssl.c
+++ b/src/streams/openssl.c
@@ -344,7 +344,7 @@ static int verify_server_cert(SSL *ssl, const char *host)
 	GENERAL_NAMES *alts;
 	struct in6_addr addr6;
 	struct in_addr addr4;
-	void *addr;
+	void *addr = NULL;
 	int i = -1, j, error = 0;
 
 	if (SSL_get_verify_result(ssl) != X509_V_OK) {
@@ -357,7 +357,7 @@ static int verify_server_cert(SSL *ssl, const char *host)
 		type = GEN_IPADD;
 		addr = &addr4;
 	} else {
-		if(p_inet_pton(AF_INET6, host, &addr6)) {
+		if (p_inet_pton(AF_INET6, host, &addr6)) {
 			type = GEN_IPADD;
 			addr = &addr6;
 		}
@@ -397,7 +397,7 @@ static int verify_server_cert(SSL *ssl, const char *host)
 					matched = 1;
 			} else if (type == GEN_IPADD) {
 				/* Here name isn't so much a name but a binary representation of the IP */
-				matched = !!memcmp(name, addr, namelen);
+				matched = addr && !!memcmp(name, addr, namelen);
 			}
 		}
 	}
diff --git a/src/tree.c b/src/tree.c
index 6a136a6..fdf36f8 100644
--- a/src/tree.c
+++ b/src/tree.c
@@ -957,7 +957,7 @@ int git_tree_entry_bypath(
 		 * walking down the path */
 		if (path[filename_len + 1] != '\0')
 			break;
-
+		/* fall through */
 	case '\0':
 		/* If there are no more components in the path, return
 		 * this entry */
diff --git a/src/util.c b/src/util.c
index 1760a31..34841df 100644
--- a/src/util.c
+++ b/src/util.c
@@ -7,10 +7,7 @@
 
 #include "util.h"
 
-#include "git2.h"
-#include <stdio.h>
-#include <ctype.h>
-#include "posix.h"
+#include "common.h"
 
 #ifdef GIT_WIN32
 # include "win32/w32_buffer.h"
@@ -478,9 +475,11 @@ uint32_t git__hash(const void *key, int len, uint32_t seed)
 
 	switch(len & 3) {
 	case 3: k1 ^= tail[2] << 16;
+		/* fall through */
 	case 2: k1 ^= tail[1] << 8;
+		/* fall through */
 	case 1: k1 ^= tail[0];
-			MURMUR_BLOCK();
+		MURMUR_BLOCK();
 	}
 
 	h1 ^= len;
diff --git a/src/util.h b/src/util.h
index 63ffa13..f6d19cf 100644
--- a/src/util.h
+++ b/src/util.h
@@ -9,12 +9,16 @@
 
 #include "common.h"
 
+#ifndef GIT_WIN32
+# include <ctype.h>
+#endif
+
 #include "git2/buffer.h"
-#include "buffer.h"
-#include "thread-utils.h"
 
+#include "buffer.h"
 #include "common.h"
 #include "strnlen.h"
+#include "thread-utils.h"
 
 #define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
 #define bitsizeof(x) (CHAR_BIT * sizeof(x))