Skip to content

Commit 07a3c99

Browse files
committed
streams: use GIT_ASSERT
1 parent 3ff56da commit 07a3c99

File tree

6 files changed

+34
-18
lines changed

6 files changed

+34
-18
lines changed

src/streams/mbedtls.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,8 @@ static int ssl_set_error(mbedtls_ssl_context *ssl, int error)
181181
char errbuf[512];
182182
int ret = -1;
183183

184-
assert(error != MBEDTLS_ERR_SSL_WANT_READ);
185-
assert(error != MBEDTLS_ERR_SSL_WANT_WRITE);
184+
GIT_ASSERT(error != MBEDTLS_ERR_SSL_WANT_READ);
185+
GIT_ASSERT(error != MBEDTLS_ERR_SSL_WANT_WRITE);
186186

187187
if (error != 0)
188188
mbedtls_strerror( error, errbuf, 512 );
@@ -423,7 +423,9 @@ int git_mbedtls_stream_new(
423423
git_stream *stream;
424424
int error;
425425

426-
assert(out && host && port);
426+
GIT_ASSERT_ARG(out);
427+
GIT_ASSERT_ARG(host);
428+
GIT_ASSERT_ARG(port);
427429

428430
if ((error = git_socket_stream_new(&stream, host, port)) < 0)
429431
return error;
@@ -442,7 +444,7 @@ int git_mbedtls__set_cert_location(const char *path, int is_dir)
442444
char errbuf[512];
443445
mbedtls_x509_crt *cacert;
444446

445-
assert(path != NULL);
447+
GIT_ASSERT_ARG(path);
446448

447449
cacert = git__malloc(sizeof(mbedtls_x509_crt));
448450
GIT_ERROR_CHECK_ALLOC(cacert);

src/streams/openssl.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -414,8 +414,8 @@ static int ssl_set_error(SSL *ssl, int error)
414414

415415
err = SSL_get_error(ssl, error);
416416

417-
assert(err != SSL_ERROR_WANT_READ);
418-
assert(err != SSL_ERROR_WANT_WRITE);
417+
GIT_ASSERT(err != SSL_ERROR_WANT_READ);
418+
GIT_ASSERT(err != SSL_ERROR_WANT_WRITE);
419419

420420
switch (err) {
421421
case SSL_ERROR_WANT_CONNECT:
@@ -757,7 +757,9 @@ static int openssl_stream_wrap(
757757
{
758758
openssl_stream *st;
759759

760-
assert(out && in && host);
760+
GIT_ASSERT_ARG(out);
761+
GIT_ASSERT_ARG(in);
762+
GIT_ASSERT_ARG(host);
761763

762764
st = git__calloc(1, sizeof(openssl_stream));
763765
GIT_ERROR_CHECK_ALLOC(st);
@@ -800,7 +802,9 @@ int git_openssl_stream_new(git_stream **out, const char *host, const char *port)
800802
git_stream *stream = NULL;
801803
int error;
802804

803-
assert(out && host && port);
805+
GIT_ASSERT_ARG(out);
806+
GIT_ASSERT_ARG(host);
807+
GIT_ASSERT_ARG(port);
804808

805809
if ((error = git_socket_stream_new(&stream, host, port)) < 0)
806810
return error;

src/streams/registry.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ int git_stream_registry_lookup(git_stream_registration *out, git_stream_t type)
5151
git_stream_registration *target;
5252
int error = GIT_ENOTFOUND;
5353

54-
assert(out);
54+
GIT_ASSERT_ARG(out);
5555

5656
switch(type) {
5757
case GIT_STREAM_STANDARD:
@@ -61,7 +61,7 @@ int git_stream_registry_lookup(git_stream_registration *out, git_stream_t type)
6161
target = &stream_registry.tls_callbacks;
6262
break;
6363
default:
64-
assert(0);
64+
git_error_set(GIT_ERROR_INVALID, "invalid stream type");
6565
return -1;
6666
}
6767

@@ -81,7 +81,7 @@ int git_stream_registry_lookup(git_stream_registration *out, git_stream_t type)
8181

8282
int git_stream_register(git_stream_t type, git_stream_registration *registration)
8383
{
84-
assert(!registration || registration->init);
84+
GIT_ASSERT(!registration || registration->init);
8585

8686
GIT_ERROR_CHECK_VERSION(registration, GIT_STREAM_VERSION, "stream_registration");
8787

src/streams/socket.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,9 @@ static int default_socket_stream_new(
183183
{
184184
git_socket_stream *st;
185185

186-
assert(out && host && port);
186+
GIT_ASSERT_ARG(out);
187+
GIT_ASSERT_ARG(host);
188+
GIT_ASSERT_ARG(port);
187189

188190
st = git__calloc(1, sizeof(git_socket_stream));
189191
GIT_ERROR_CHECK_ALLOC(st);
@@ -217,7 +219,9 @@ int git_socket_stream_new(
217219
git_stream_registration custom = {0};
218220
int error;
219221

220-
assert(out && host && port);
222+
GIT_ASSERT_ARG(out);
223+
GIT_ASSERT_ARG(host);
224+
GIT_ASSERT_ARG(port);
221225

222226
if ((error = git_stream_registry_lookup(&custom, GIT_STREAM_STANDARD)) == 0)
223227
init = custom.init;

src/streams/stransport.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ static ssize_t stransport_write(git_stream *stream, const char *data, size_t len
167167
if ((ret = SSLWrite(st->ctx, data, data_len, &processed)) != noErr)
168168
return stransport_error(ret);
169169

170-
assert(processed < SSIZE_MAX);
170+
GIT_ASSERT(processed < SSIZE_MAX);
171171
return (ssize_t)processed;
172172
}
173173

@@ -251,7 +251,9 @@ static int stransport_wrap(
251251
stransport_stream *st;
252252
OSStatus ret;
253253

254-
assert(out && in && host);
254+
GIT_ASSERT_ARG(out);
255+
GIT_ASSERT_ARG(in);
256+
GIT_ASSERT_ARG(host);
255257

256258
st = git__calloc(1, sizeof(stransport_stream));
257259
GIT_ERROR_CHECK_ALLOC(st);
@@ -305,7 +307,8 @@ int git_stransport_stream_new(git_stream **out, const char *host, const char *po
305307
git_stream *stream = NULL;
306308
int error;
307309

308-
assert(out && host);
310+
GIT_ASSERT_ARG(out);
311+
GIT_ASSERT_ARG(host);
309312

310313
error = git_socket_stream_new(&stream, host, port);
311314

src/streams/tls.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ int git_tls_stream_new(git_stream **out, const char *host, const char *port)
2020
git_stream_registration custom = {0};
2121
int error;
2222

23-
assert(out && host && port);
23+
GIT_ASSERT_ARG(out);
24+
GIT_ASSERT_ARG(host);
25+
GIT_ASSERT_ARG(port);
2426

2527
if ((error = git_stream_registry_lookup(&custom, GIT_STREAM_TLS)) == 0) {
2628
init = custom.init;
@@ -49,7 +51,8 @@ int git_tls_stream_wrap(git_stream **out, git_stream *in, const char *host)
4951
int (*wrap)(git_stream **, git_stream *, const char *) = NULL;
5052
git_stream_registration custom = {0};
5153

52-
assert(out && in);
54+
GIT_ASSERT_ARG(out);
55+
GIT_ASSERT_ARG(in);
5356

5457
if (git_stream_registry_lookup(&custom, GIT_STREAM_TLS) == 0) {
5558
wrap = custom.wrap;

0 commit comments

Comments
 (0)