Commit 07a3c992 by Edward Thomson

streams: use GIT_ASSERT

parent 3ff56dae
...@@ -181,8 +181,8 @@ static int ssl_set_error(mbedtls_ssl_context *ssl, int error) ...@@ -181,8 +181,8 @@ static int ssl_set_error(mbedtls_ssl_context *ssl, int error)
char errbuf[512]; char errbuf[512];
int ret = -1; int ret = -1;
assert(error != MBEDTLS_ERR_SSL_WANT_READ); GIT_ASSERT(error != MBEDTLS_ERR_SSL_WANT_READ);
assert(error != MBEDTLS_ERR_SSL_WANT_WRITE); GIT_ASSERT(error != MBEDTLS_ERR_SSL_WANT_WRITE);
if (error != 0) if (error != 0)
mbedtls_strerror( error, errbuf, 512 ); mbedtls_strerror( error, errbuf, 512 );
...@@ -423,7 +423,9 @@ int git_mbedtls_stream_new( ...@@ -423,7 +423,9 @@ int git_mbedtls_stream_new(
git_stream *stream; git_stream *stream;
int error; 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) if ((error = git_socket_stream_new(&stream, host, port)) < 0)
return error; return error;
...@@ -442,7 +444,7 @@ int git_mbedtls__set_cert_location(const char *path, int is_dir) ...@@ -442,7 +444,7 @@ int git_mbedtls__set_cert_location(const char *path, int is_dir)
char errbuf[512]; char errbuf[512];
mbedtls_x509_crt *cacert; mbedtls_x509_crt *cacert;
assert(path != NULL); GIT_ASSERT_ARG(path);
cacert = git__malloc(sizeof(mbedtls_x509_crt)); cacert = git__malloc(sizeof(mbedtls_x509_crt));
GIT_ERROR_CHECK_ALLOC(cacert); GIT_ERROR_CHECK_ALLOC(cacert);
......
...@@ -414,8 +414,8 @@ static int ssl_set_error(SSL *ssl, int error) ...@@ -414,8 +414,8 @@ static int ssl_set_error(SSL *ssl, int error)
err = SSL_get_error(ssl, error); err = SSL_get_error(ssl, error);
assert(err != SSL_ERROR_WANT_READ); GIT_ASSERT(err != SSL_ERROR_WANT_READ);
assert(err != SSL_ERROR_WANT_WRITE); GIT_ASSERT(err != SSL_ERROR_WANT_WRITE);
switch (err) { switch (err) {
case SSL_ERROR_WANT_CONNECT: case SSL_ERROR_WANT_CONNECT:
...@@ -757,7 +757,9 @@ static int openssl_stream_wrap( ...@@ -757,7 +757,9 @@ static int openssl_stream_wrap(
{ {
openssl_stream *st; 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)); st = git__calloc(1, sizeof(openssl_stream));
GIT_ERROR_CHECK_ALLOC(st); GIT_ERROR_CHECK_ALLOC(st);
...@@ -800,7 +802,9 @@ int git_openssl_stream_new(git_stream **out, const char *host, const char *port) ...@@ -800,7 +802,9 @@ int git_openssl_stream_new(git_stream **out, const char *host, const char *port)
git_stream *stream = NULL; git_stream *stream = NULL;
int error; 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) if ((error = git_socket_stream_new(&stream, host, port)) < 0)
return error; return error;
......
...@@ -51,7 +51,7 @@ int git_stream_registry_lookup(git_stream_registration *out, git_stream_t type) ...@@ -51,7 +51,7 @@ int git_stream_registry_lookup(git_stream_registration *out, git_stream_t type)
git_stream_registration *target; git_stream_registration *target;
int error = GIT_ENOTFOUND; int error = GIT_ENOTFOUND;
assert(out); GIT_ASSERT_ARG(out);
switch(type) { switch(type) {
case GIT_STREAM_STANDARD: case GIT_STREAM_STANDARD:
...@@ -61,7 +61,7 @@ int git_stream_registry_lookup(git_stream_registration *out, git_stream_t type) ...@@ -61,7 +61,7 @@ int git_stream_registry_lookup(git_stream_registration *out, git_stream_t type)
target = &stream_registry.tls_callbacks; target = &stream_registry.tls_callbacks;
break; break;
default: default:
assert(0); git_error_set(GIT_ERROR_INVALID, "invalid stream type");
return -1; return -1;
} }
...@@ -81,7 +81,7 @@ int git_stream_registry_lookup(git_stream_registration *out, git_stream_t type) ...@@ -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) 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"); GIT_ERROR_CHECK_VERSION(registration, GIT_STREAM_VERSION, "stream_registration");
......
...@@ -183,7 +183,9 @@ static int default_socket_stream_new( ...@@ -183,7 +183,9 @@ static int default_socket_stream_new(
{ {
git_socket_stream *st; 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)); st = git__calloc(1, sizeof(git_socket_stream));
GIT_ERROR_CHECK_ALLOC(st); GIT_ERROR_CHECK_ALLOC(st);
...@@ -217,7 +219,9 @@ int git_socket_stream_new( ...@@ -217,7 +219,9 @@ int git_socket_stream_new(
git_stream_registration custom = {0}; git_stream_registration custom = {0};
int error; 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) if ((error = git_stream_registry_lookup(&custom, GIT_STREAM_STANDARD)) == 0)
init = custom.init; init = custom.init;
......
...@@ -167,7 +167,7 @@ static ssize_t stransport_write(git_stream *stream, const char *data, size_t len ...@@ -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) if ((ret = SSLWrite(st->ctx, data, data_len, &processed)) != noErr)
return stransport_error(ret); return stransport_error(ret);
assert(processed < SSIZE_MAX); GIT_ASSERT(processed < SSIZE_MAX);
return (ssize_t)processed; return (ssize_t)processed;
} }
...@@ -251,7 +251,9 @@ static int stransport_wrap( ...@@ -251,7 +251,9 @@ static int stransport_wrap(
stransport_stream *st; stransport_stream *st;
OSStatus ret; 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)); st = git__calloc(1, sizeof(stransport_stream));
GIT_ERROR_CHECK_ALLOC(st); GIT_ERROR_CHECK_ALLOC(st);
...@@ -305,7 +307,8 @@ int git_stransport_stream_new(git_stream **out, const char *host, const char *po ...@@ -305,7 +307,8 @@ int git_stransport_stream_new(git_stream **out, const char *host, const char *po
git_stream *stream = NULL; git_stream *stream = NULL;
int error; int error;
assert(out && host); GIT_ASSERT_ARG(out);
GIT_ASSERT_ARG(host);
error = git_socket_stream_new(&stream, host, port); error = git_socket_stream_new(&stream, host, port);
......
...@@ -20,7 +20,9 @@ int git_tls_stream_new(git_stream **out, const char *host, const char *port) ...@@ -20,7 +20,9 @@ int git_tls_stream_new(git_stream **out, const char *host, const char *port)
git_stream_registration custom = {0}; git_stream_registration custom = {0};
int error; 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) { if ((error = git_stream_registry_lookup(&custom, GIT_STREAM_TLS)) == 0) {
init = custom.init; init = custom.init;
...@@ -49,7 +51,8 @@ int git_tls_stream_wrap(git_stream **out, git_stream *in, const char *host) ...@@ -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; int (*wrap)(git_stream **, git_stream *, const char *) = NULL;
git_stream_registration custom = {0}; 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) { if (git_stream_registry_lookup(&custom, GIT_STREAM_TLS) == 0) {
wrap = custom.wrap; wrap = custom.wrap;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment