streams: use GIT_ASSERT
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
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;