Commit c6ebdb296bc44b50fa76e492f57f086bf6c9ec08

Edward Thomson 2020-11-22T09:43:06

win32: use GIT_ASSERT

diff --git a/src/unix/map.c b/src/unix/map.c
index 7f9076e..62c5257 100644
--- a/src/unix/map.c
+++ b/src/unix/map.c
@@ -66,7 +66,7 @@ int p_mmap(git_map *out, size_t len, int prot, int flags, int fd, off64_t offset
 
 int p_munmap(git_map *map)
 {
-	assert(map != NULL);
+	GIT_ASSERT_ARG(map);
 	munmap(map->data, map->len);
 
 	return 0;
diff --git a/src/win32/findfile.c b/src/win32/findfile.c
index 7f077e1..f541a03 100644
--- a/src/win32/findfile.c
+++ b/src/win32/findfile.c
@@ -53,7 +53,9 @@ static wchar_t* win32_walkpath(wchar_t *path, wchar_t *buf, size_t buflen)
 {
 	wchar_t term, *base = path;
 
-	assert(path && buf && buflen);
+	GIT_ASSERT_ARG_WITH_RETVAL(path, NULL);
+	GIT_ASSERT_ARG_WITH_RETVAL(buf, NULL);
+	GIT_ASSERT_ARG_WITH_RETVAL(buflen, NULL);
 
 	term = (*path == L'"') ? *path++ : L';';
 
@@ -109,7 +111,7 @@ static int win32_find_git_in_registry(
 	HKEY hKey;
 	int error = GIT_ENOTFOUND;
 
-	assert(buf);
+	GIT_ASSERT_ARG(buf);
 
 	if (!RegOpenKeyExW(hive, key, 0, KEY_READ, &hKey)) {
 		DWORD dwType, cbData;
diff --git a/src/win32/map.c b/src/win32/map.c
index e2ce737..2aabc9b 100644
--- a/src/win32/map.c
+++ b/src/win32/map.c
@@ -117,7 +117,7 @@ int p_munmap(git_map *map)
 {
 	int error = 0;
 
-	assert(map != NULL);
+	GIT_ASSERT_ARG(map);
 
 	if (map->data) {
 		if (!UnmapViewOfFile(map->data)) {
diff --git a/src/win32/path_w32.c b/src/win32/path_w32.c
index 9faddcf..23efd92 100644
--- a/src/win32/path_w32.c
+++ b/src/win32/path_w32.c
@@ -492,14 +492,12 @@ size_t git_win32_path_remove_namespace(wchar_t *str, size_t len)
 		prefix_len = CONST_STRLEN(unc_prefix);
 	}
 
-	if (remainder) {
-		/*
-		 * Sanity check that the new string isn't longer than the old one.
-		 * (This could only happen due to programmer error introducing a
-		 * prefix longer than the namespace it replaces.)
-		 */
-		assert(len >= remainder_len + prefix_len);
-
+	/*
+	 * Sanity check that the new string isn't longer than the old one.
+	 * (This could only happen due to programmer error introducing a
+	 * prefix longer than the namespace it replaces.)
+	 */
+	if (remainder && len >= remainder_len + prefix_len) {
 		if (prefix)
 			memmove(str, prefix, prefix_len * sizeof(wchar_t));
 
diff --git a/src/win32/precompiled.h b/src/win32/precompiled.h
index 314383d..806b169 100644
--- a/src/win32/precompiled.h
+++ b/src/win32/precompiled.h
@@ -1,6 +1,5 @@
 #include "common.h"
 
-#include <assert.h>
 #include <errno.h>
 #include <limits.h>
 #include <stdlib.h>
diff --git a/src/win32/thread.c b/src/win32/thread.c
index 51b005b..f5cacd3 100644
--- a/src/win32/thread.c
+++ b/src/win32/thread.c
@@ -94,10 +94,7 @@ int git_thread_join(
 
 	/* Check for the thread having exited uncleanly. If exit was unclean,
 	 * then we don't have a return value to give back to the caller. */
-	if (exit != CLEAN_THREAD_EXIT) {
-		assert(false);
-		thread->result = NULL;
-	}
+	GIT_ASSERT(exit == CLEAN_THREAD_EXIT);
 
 	if (value_ptr)
 		*value_ptr = thread->result;
@@ -149,7 +146,7 @@ int git_cond_init(git_cond *cond)
 {
 	/* This is an auto-reset event. */
 	*cond = CreateEventW(NULL, FALSE, FALSE, NULL);
-	assert(*cond);
+	GIT_ASSERT(*cond);
 
 	/* If we can't create the event, claim that the reason was out-of-memory.
 	 * The actual reason can be fetched with GetLastError(). */
@@ -164,7 +161,7 @@ int git_cond_free(git_cond *cond)
 		return EINVAL;
 
 	closed = CloseHandle(*cond);
-	assert(closed);
+	GIT_ASSERT(closed);
 	GIT_UNUSED(closed);
 
 	*cond = NULL;
@@ -186,7 +183,7 @@ int git_cond_wait(git_cond *cond, git_mutex *mutex)
 		return error;
 
 	wait_result = WaitForSingleObject(*cond, INFINITE);
-	assert(WAIT_OBJECT_0 == wait_result);
+	GIT_ASSERT(WAIT_OBJECT_0 == wait_result);
 	GIT_UNUSED(wait_result);
 
 	return git_mutex_lock(mutex);
@@ -200,7 +197,7 @@ int git_cond_signal(git_cond *cond)
 		return EINVAL;
 
 	signaled = SetEvent(*cond);
-	assert(signaled);
+	GIT_ASSERT(signaled);
 	GIT_UNUSED(signaled);
 
 	return 0;
diff --git a/src/win32/w32_buffer.c b/src/win32/w32_buffer.c
index b78a7e6..f270a1e 100644
--- a/src/win32/w32_buffer.c
+++ b/src/win32/w32_buffer.c
@@ -32,13 +32,13 @@ int git_buf_put_w(git_buf *buf, const wchar_t *string_w, size_t len_w)
 		return -1;
 	}
 
-	assert(string_w);
+	GIT_ASSERT(string_w);
 
 	/* Measure the string necessary for conversion */
 	if ((utf8_len = WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, string_w, (int)len_w, NULL, 0, NULL, NULL)) == 0)
 		return 0;
 
-	assert(utf8_len > 0);
+	GIT_ASSERT(utf8_len > 0);
 
 	GIT_ERROR_CHECK_ALLOC_ADD(&new_size, buf->size, (size_t)utf8_len);
 	GIT_ERROR_CHECK_ALLOC_ADD(&new_size, new_size, 1);
@@ -50,7 +50,7 @@ int git_buf_put_w(git_buf *buf, const wchar_t *string_w, size_t len_w)
 			CP_UTF8, WC_ERR_INVALID_CHARS, string_w, (int)len_w, &buf->ptr[buf->size], utf8_len, NULL, NULL)) == 0)
 		return handle_wc_error();
 
-	assert(utf8_write_len == utf8_len);
+	GIT_ASSERT(utf8_write_len == utf8_len);
 
 	buf->size += utf8_write_len;
 	buf->ptr[buf->size] = '\0';