Commit 0511b15c82a6af253d9bd18ddeed85f8afd28ddd

Vicent Marti 2014-03-03T15:05:26

Merge pull request #2141 from ravselj/development BUGFIX - Fetching twice from the same remote causes a segfault

diff --git a/CMakeLists.txt b/CMakeLists.txt
index d6b3275..cca2a12 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -57,6 +57,10 @@ IF(MSVC)
 	# By default, libgit2 is built with WinHTTP.  To use the built-in
 	# HTTP transport, invoke CMake with the "-DWINHTTP=OFF" argument.
 	OPTION( WINHTTP			"Use Win32 WinHTTP routines"	ON  )
+
+	ADD_DEFINITIONS(-D_SCL_SECURE_NO_WARNINGS)
+	ADD_DEFINITIONS(-D_CRT_SECURE_NO_DEPRECATE)
+	ADD_DEFINITIONS(-D_CRT_NONSTDC_NO_DEPRECATE)
 ENDIF()
 
 # This variable will contain the libraries we need to put into
diff --git a/examples/add.c b/examples/add.c
index 336596b..0c6076e 100644
--- a/examples/add.c
+++ b/examples/add.c
@@ -78,7 +78,7 @@ int print_matched_cb(const char *path, const char *matched_pathspec, void *paylo
 	git_status_t status;
 	(void)matched_pathspec;
 
-	if (git_status_file(&status, p.repo, path)) {
+	if (git_status_file((unsigned int*)(&status), p.repo, path)) {
 		return -1; //abort
 	}
 
diff --git a/examples/blame.c b/examples/blame.c
index 6bc0581..fda605b 100644
--- a/examples/blame.c
+++ b/examples/blame.c
@@ -107,8 +107,9 @@ int main(int argc, char *argv[])
 		if (break_on_null_hunk && !hunk) break;
 
 		if (hunk) {
-			break_on_null_hunk = 1;
 			char sig[128] = {0};
+			break_on_null_hunk = 1;
+			
 
 			git_oid_tostr(oid, 10, &hunk->final_commit_id);
 			snprintf(sig, 30, "%s <%s>", hunk->final_signature->name, hunk->final_signature->email);
diff --git a/examples/cat-file.c b/examples/cat-file.c
index fa6add0..52399fa 100644
--- a/examples/cat-file.c
+++ b/examples/cat-file.c
@@ -42,7 +42,7 @@ static void print_signature(const char *header, const git_signature *sig)
 static void show_blob(const git_blob *blob)
 {
 	/* ? Does this need crlf filtering? */
-	fwrite(git_blob_rawcontent(blob), git_blob_rawsize(blob), 1, stdout);
+	fwrite(git_blob_rawcontent(blob), (size_t)git_blob_rawsize(blob), 1, stdout);
 }
 
 /** Show each entry with its type, id and attributes */
diff --git a/examples/common.c b/examples/common.c
index 12dbccf..a066c15 100644
--- a/examples/common.c
+++ b/examples/common.c
@@ -156,7 +156,7 @@ int diff_output(
 	const git_diff_line *l,
 	void *p)
 {
-	FILE *fp = p;
+	FILE *fp = (FILE*)p;
 
 	(void)d; (void)h;
 
diff --git a/examples/network/clone.c b/examples/network/clone.c
index 4df47eb..a982c13 100644
--- a/examples/network/clone.c
+++ b/examples/network/clone.c
@@ -22,7 +22,7 @@ static void print_progress(const progress_data *pd)
 	int index_percent = (100*pd->fetch_progress.indexed_objects) / pd->fetch_progress.total_objects;
 	int checkout_percent = pd->total_steps > 0
 		? (100 * pd->completed_steps) / pd->total_steps
-		: 0.f;
+		: 0;
 	int kbytes = pd->fetch_progress.received_bytes / 1024;
 
 	if (pd->fetch_progress.received_objects == pd->fetch_progress.total_objects) {
diff --git a/src/fetch.c b/src/fetch.c
index 5bf2b93..c7d2c83 100644
--- a/src/fetch.c
+++ b/src/fetch.c
@@ -42,8 +42,10 @@ static int maybe_want(git_remote *remote, git_remote_head *head, git_odb *odb, g
 		return 0;
 
 	/* If we have the object, mark it so we don't ask for it */
-	if (git_odb_exists(odb, &head->oid))
+	if (git_odb_exists(odb, &head->oid)) {
 		head->local = 1;
+		remote->need_pack = 0;
+	}
 	else
 		remote->need_pack = 1;
 
diff --git a/src/transports/smart_protocol.c b/src/transports/smart_protocol.c
index dd9b5e0..7e8fcdd 100644
--- a/src/transports/smart_protocol.c
+++ b/src/transports/smart_protocol.c
@@ -579,6 +579,10 @@ int git_smart__download_pack(
 done:
 	if (writepack)
 		writepack->free(writepack);
+	if (progress_cb) {
+		t->packetsize_cb = NULL;
+		t->packetsize_payload = NULL;
+	}
 
 	return error;
 }
diff --git a/src/transports/ssh.c b/src/transports/ssh.c
index 37f1708..bece0b4 100644
--- a/src/transports/ssh.c
+++ b/src/transports/ssh.c
@@ -53,6 +53,7 @@ static void ssh_error(LIBSSH2_SESSION *session, const char *errmsg)
 static int gen_proto(git_buf *request, const char *cmd, const char *url)
 {
 	char *repo;
+	int len;
 
 	if (!git__prefixcmp(url, prefix_ssh)) {
 		url = url + strlen(prefix_ssh);
@@ -67,7 +68,7 @@ static int gen_proto(git_buf *request, const char *cmd, const char *url)
 		return -1;
 	}
 
-	int len = strlen(cmd) + 1 /* Space */ + 1 /* Quote */ + strlen(repo) + 1 /* Quote */ + 1;
+	len = strlen(cmd) + 1 /* Space */ + 1 /* Quote */ + strlen(repo) + 1 /* Quote */ + 1;
 
 	git_buf_grow(request, len);
 	git_buf_printf(request, "%s '%s'", cmd, repo);