Commit 07a3c9928aa36cfd6f02d500222ed6cb22eeeed1

Edward Thomson 2020-11-21T23:52:39

streams: use GIT_ASSERT

diff --git a/src/streams/mbedtls.c b/src/streams/mbedtls.c
index 00daa55..22b9f47 100644
--- a/src/streams/mbedtls.c
+++ b/src/streams/mbedtls.c
@@ -181,8 +181,8 @@ static int ssl_set_error(mbedtls_ssl_context *ssl, int error)
 	char errbuf[512];
 	int ret = -1;
 
-	assert(error != MBEDTLS_ERR_SSL_WANT_READ);
-	assert(error != MBEDTLS_ERR_SSL_WANT_WRITE);
+	GIT_ASSERT(error != MBEDTLS_ERR_SSL_WANT_READ);
+	GIT_ASSERT(error != MBEDTLS_ERR_SSL_WANT_WRITE);
 
 	if (error != 0)
 		mbedtls_strerror( error, errbuf, 512 );
@@ -423,7 +423,9 @@ int git_mbedtls_stream_new(
 	git_stream *stream;
 	int error;
 
-	assert(out && host && port);
+	GIT_ASSERT_ARG(out);
+	GIT_ASSERT_ARG(host);
+	GIT_ASSERT_ARG(port);
 
 	if ((error = git_socket_stream_new(&stream, host, port)) < 0)
 		return error;
@@ -442,7 +444,7 @@ int git_mbedtls__set_cert_location(const char *path, int is_dir)
 	char errbuf[512];
 	mbedtls_x509_crt *cacert;
 
-	assert(path != NULL);
+	GIT_ASSERT_ARG(path);
 
 	cacert = git__malloc(sizeof(mbedtls_x509_crt));
 	GIT_ERROR_CHECK_ALLOC(cacert);
diff --git a/src/streams/openssl.c b/src/streams/openssl.c
index 0a0c2c5..d866832 100644
--- a/src/streams/openssl.c
+++ b/src/streams/openssl.c
@@ -414,8 +414,8 @@ static int ssl_set_error(SSL *ssl, int error)
 
 	err = SSL_get_error(ssl, error);
 
-	assert(err != SSL_ERROR_WANT_READ);
-	assert(err != SSL_ERROR_WANT_WRITE);
+	GIT_ASSERT(err != SSL_ERROR_WANT_READ);
+	GIT_ASSERT(err != SSL_ERROR_WANT_WRITE);
 
 	switch (err) {
 	case SSL_ERROR_WANT_CONNECT:
@@ -757,7 +757,9 @@ static int openssl_stream_wrap(
 {
 	openssl_stream *st;
 
-	assert(out && in && host);
+	GIT_ASSERT_ARG(out);
+	GIT_ASSERT_ARG(in);
+	GIT_ASSERT_ARG(host);
 
 	st = git__calloc(1, sizeof(openssl_stream));
 	GIT_ERROR_CHECK_ALLOC(st);
@@ -800,7 +802,9 @@ int git_openssl_stream_new(git_stream **out, const char *host, const char *port)
 	git_stream *stream = NULL;
 	int error;
 
-	assert(out && host && port);
+	GIT_ASSERT_ARG(out);
+	GIT_ASSERT_ARG(host);
+	GIT_ASSERT_ARG(port);
 
 	if ((error = git_socket_stream_new(&stream, host, port)) < 0)
 		return error;
diff --git a/src/streams/registry.c b/src/streams/registry.c
index b3bf17a..e60e1cd 100644
--- a/src/streams/registry.c
+++ b/src/streams/registry.c
@@ -51,7 +51,7 @@ int git_stream_registry_lookup(git_stream_registration *out, git_stream_t type)
 	git_stream_registration *target;
 	int error = GIT_ENOTFOUND;
 
-	assert(out);
+	GIT_ASSERT_ARG(out);
 
 	switch(type) {
 	case GIT_STREAM_STANDARD:
@@ -61,7 +61,7 @@ int git_stream_registry_lookup(git_stream_registration *out, git_stream_t type)
 		target = &stream_registry.tls_callbacks;
 		break;
 	default:
-		assert(0);
+		git_error_set(GIT_ERROR_INVALID, "invalid stream type");
 		return -1;
 	}
 
@@ -81,7 +81,7 @@ int git_stream_registry_lookup(git_stream_registration *out, git_stream_t type)
 
 int git_stream_register(git_stream_t type, git_stream_registration *registration)
 {
-	assert(!registration || registration->init);
+	GIT_ASSERT(!registration || registration->init);
 
 	GIT_ERROR_CHECK_VERSION(registration, GIT_STREAM_VERSION, "stream_registration");
 
diff --git a/src/streams/socket.c b/src/streams/socket.c
index 33f7883..9415fe8 100644
--- a/src/streams/socket.c
+++ b/src/streams/socket.c
@@ -183,7 +183,9 @@ static int default_socket_stream_new(
 {
 	git_socket_stream *st;
 
-	assert(out && host && port);
+	GIT_ASSERT_ARG(out);
+	GIT_ASSERT_ARG(host);
+	GIT_ASSERT_ARG(port);
 
 	st = git__calloc(1, sizeof(git_socket_stream));
 	GIT_ERROR_CHECK_ALLOC(st);
@@ -217,7 +219,9 @@ int git_socket_stream_new(
 	git_stream_registration custom = {0};
 	int error;
 
-	assert(out && host && port);
+	GIT_ASSERT_ARG(out);
+	GIT_ASSERT_ARG(host);
+	GIT_ASSERT_ARG(port);
 
 	if ((error = git_stream_registry_lookup(&custom, GIT_STREAM_STANDARD)) == 0)
 		init = custom.init;
diff --git a/src/streams/stransport.c b/src/streams/stransport.c
index a79d3cb..3f31d25 100644
--- a/src/streams/stransport.c
+++ b/src/streams/stransport.c
@@ -167,7 +167,7 @@ static ssize_t stransport_write(git_stream *stream, const char *data, size_t len
 	if ((ret = SSLWrite(st->ctx, data, data_len, &processed)) != noErr)
 		return stransport_error(ret);
 
-	assert(processed < SSIZE_MAX);
+	GIT_ASSERT(processed < SSIZE_MAX);
 	return (ssize_t)processed;
 }
 
@@ -251,7 +251,9 @@ static int stransport_wrap(
 	stransport_stream *st;
 	OSStatus ret;
 
-	assert(out && in && host);
+	GIT_ASSERT_ARG(out);
+	GIT_ASSERT_ARG(in);
+	GIT_ASSERT_ARG(host);
 
 	st = git__calloc(1, sizeof(stransport_stream));
 	GIT_ERROR_CHECK_ALLOC(st);
@@ -305,7 +307,8 @@ int git_stransport_stream_new(git_stream **out, const char *host, const char *po
 	git_stream *stream = NULL;
 	int error;
 
-	assert(out && host);
+	GIT_ASSERT_ARG(out);
+	GIT_ASSERT_ARG(host);
 
 	error = git_socket_stream_new(&stream, host, port);
 
diff --git a/src/streams/tls.c b/src/streams/tls.c
index 255a4a0..e063a33 100644
--- a/src/streams/tls.c
+++ b/src/streams/tls.c
@@ -20,7 +20,9 @@ int git_tls_stream_new(git_stream **out, const char *host, const char *port)
 	git_stream_registration custom = {0};
 	int error;
 
-	assert(out && host && port);
+	GIT_ASSERT_ARG(out);
+	GIT_ASSERT_ARG(host);
+	GIT_ASSERT_ARG(port);
 
 	if ((error = git_stream_registry_lookup(&custom, GIT_STREAM_TLS)) == 0) {
 		init = custom.init;
@@ -49,7 +51,8 @@ int git_tls_stream_wrap(git_stream **out, git_stream *in, const char *host)
 	int (*wrap)(git_stream **, git_stream *, const char *) = NULL;
 	git_stream_registration custom = {0};
 
-	assert(out && in);
+	GIT_ASSERT_ARG(out);
+	GIT_ASSERT_ARG(in);
 
 	if (git_stream_registry_lookup(&custom, GIT_STREAM_TLS) == 0) {
 		wrap = custom.wrap;