Skip to content

Commit 4f5f112

Browse files
committed
transports: use GIT_ASSERT
1 parent 07a3c99 commit 4f5f112

File tree

10 files changed

+86
-59
lines changed

10 files changed

+86
-59
lines changed

src/transports/auth_negotiate.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ static int negotiate_set_challenge(
6565
{
6666
http_auth_negotiate_context *ctx = (http_auth_negotiate_context *)c;
6767

68-
assert(ctx && ctx->configured && challenge);
68+
GIT_ASSERT_ARG(ctx);
69+
GIT_ASSERT_ARG(challenge);
70+
GIT_ASSERT(ctx->configured);
6971

7072
git__free(ctx->challenge);
7173

@@ -108,7 +110,12 @@ static int negotiate_next_token(
108110
size_t challenge_len;
109111
int error = 0;
110112

111-
assert(buf && ctx && ctx->configured && cred && cred->credtype == GIT_CREDENTIAL_DEFAULT);
113+
GIT_ASSERT_ARG(buf);
114+
GIT_ASSERT_ARG(ctx);
115+
GIT_ASSERT_ARG(cred);
116+
117+
GIT_ASSERT(ctx->configured);
118+
GIT_ASSERT(cred->credtype == GIT_CREDENTIAL_DEFAULT);
112119

113120
if (ctx->complete)
114121
return 0;
@@ -202,7 +209,7 @@ static int negotiate_is_complete(git_http_auth_context *c)
202209
{
203210
http_auth_negotiate_context *ctx = (http_auth_negotiate_context *)c;
204211

205-
assert(ctx);
212+
GIT_ASSERT_ARG(ctx);
206213

207214
return (ctx->complete == 1);
208215
}

src/transports/auth_ntlm.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ static int ntlm_set_challenge(
2929
{
3030
http_auth_ntlm_context *ctx = (http_auth_ntlm_context *)c;
3131

32-
assert(ctx && challenge);
32+
GIT_ASSERT_ARG(ctx);
33+
GIT_ASSERT_ARG(challenge);
3334

3435
git__free(ctx->challenge);
3536

@@ -46,7 +47,7 @@ static int ntlm_set_credentials(http_auth_ntlm_context *ctx, git_credential *_cr
4647
char *domain = NULL, *domainuser = NULL;
4748
int error = 0;
4849

49-
assert(_cred->credtype == GIT_CREDENTIAL_USERPASS_PLAINTEXT);
50+
GIT_ASSERT(_cred->credtype == GIT_CREDENTIAL_USERPASS_PLAINTEXT);
5051
cred = (git_credential_userpass_plaintext *)_cred;
5152

5253
if ((sep = strchr(cred->username, '\\')) != NULL) {
@@ -86,7 +87,10 @@ static int ntlm_next_token(
8687
size_t challenge_len, msg_len;
8788
int error = -1;
8889

89-
assert(buf && ctx && ctx->ntlm);
90+
GIT_ASSERT_ARG(buf);
91+
GIT_ASSERT_ARG(ctx);
92+
93+
GIT_ASSERT(ctx->ntlm);
9094

9195
challenge_len = ctx->challenge ? strlen(ctx->challenge) : 0;
9296

@@ -162,7 +166,7 @@ static int ntlm_is_complete(git_http_auth_context *c)
162166
{
163167
http_auth_ntlm_context *ctx = (http_auth_ntlm_context *)c;
164168

165-
assert(ctx);
169+
GIT_ASSERT_ARG(ctx);
166170
return (ctx->complete == true);
167171
}
168172

src/transports/credential.c

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,9 @@ int git_credential_userpass_plaintext_new(
8585
{
8686
git_credential_userpass_plaintext *c;
8787

88-
assert(cred && username && password);
88+
GIT_ASSERT_ARG(cred);
89+
GIT_ASSERT_ARG(username);
90+
GIT_ASSERT_ARG(password);
8991

9092
c = git__malloc(sizeof(git_credential_userpass_plaintext));
9193
GIT_ERROR_CHECK_ALLOC(c);
@@ -233,7 +235,9 @@ static int git_credential_ssh_key_type_new(
233235
{
234236
git_credential_ssh_key *c;
235237

236-
assert(username && cred && privatekey);
238+
GIT_ASSERT_ARG(username);
239+
GIT_ASSERT_ARG(cred);
240+
GIT_ASSERT_ARG(privatekey);
237241

238242
c = git__calloc(1, sizeof(git_credential_ssh_key));
239243
GIT_ERROR_CHECK_ALLOC(c);
@@ -269,7 +273,9 @@ int git_credential_ssh_interactive_new(
269273
{
270274
git_credential_ssh_interactive *c;
271275

272-
assert(out && username && prompt_callback);
276+
GIT_ASSERT_ARG(out);
277+
GIT_ASSERT_ARG(username);
278+
GIT_ASSERT_ARG(prompt_callback);
273279

274280
c = git__calloc(1, sizeof(git_credential_ssh_interactive));
275281
GIT_ERROR_CHECK_ALLOC(c);
@@ -290,7 +296,8 @@ int git_credential_ssh_interactive_new(
290296
int git_credential_ssh_key_from_agent(git_credential **cred, const char *username) {
291297
git_credential_ssh_key *c;
292298

293-
assert(username && cred);
299+
GIT_ASSERT_ARG(username);
300+
GIT_ASSERT_ARG(cred);
294301

295302
c = git__calloc(1, sizeof(git_credential_ssh_key));
296303
GIT_ERROR_CHECK_ALLOC(c);
@@ -317,7 +324,8 @@ int git_credential_ssh_custom_new(
317324
{
318325
git_credential_ssh_custom *c;
319326

320-
assert(username && cred);
327+
GIT_ASSERT_ARG(username);
328+
GIT_ASSERT_ARG(cred);
321329

322330
c = git__calloc(1, sizeof(git_credential_ssh_custom));
323331
GIT_ERROR_CHECK_ALLOC(c);
@@ -347,7 +355,7 @@ int git_credential_default_new(git_credential **cred)
347355
{
348356
git_credential_default *c;
349357

350-
assert(cred);
358+
GIT_ASSERT_ARG(cred);
351359

352360
c = git__calloc(1, sizeof(git_credential_default));
353361
GIT_ERROR_CHECK_ALLOC(c);
@@ -364,7 +372,7 @@ int git_credential_username_new(git_credential **cred, const char *username)
364372
git_credential_username *c;
365373
size_t len, allocsize;
366374

367-
assert(cred);
375+
GIT_ASSERT_ARG(cred);
368376

369377
len = strlen(username);
370378

src/transports/git.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ static int _git_close(git_smart_subtransport *subtransport)
327327
{
328328
git_subtransport *t = (git_subtransport *) subtransport;
329329

330-
assert(!t->current_stream);
330+
GIT_ASSERT(!t->current_stream);
331331

332332
GIT_UNUSED(t);
333333

@@ -338,8 +338,6 @@ static void _git_free(git_smart_subtransport *subtransport)
338338
{
339339
git_subtransport *t = (git_subtransport *) subtransport;
340340

341-
assert(!t->current_stream);
342-
343341
git__free(t);
344342
}
345343

src/transports/http.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ static int http_stream_read(
416416
goto done;
417417
}
418418

419-
assert (stream->state == HTTP_STATE_RECEIVING_RESPONSE);
419+
GIT_ASSERT(stream->state == HTTP_STATE_RECEIVING_RESPONSE);
420420

421421
error = git_http_client_read_body(transport->http_client, buffer, buffer_size);
422422

@@ -554,7 +554,7 @@ static int http_stream_write(
554554
goto done;
555555
}
556556

557-
assert(stream->state == HTTP_STATE_SENDING_REQUEST);
557+
GIT_ASSERT(stream->state == HTTP_STATE_SENDING_REQUEST);
558558

559559
error = git_http_client_send_body(transport->http_client, buffer, len);
560560

@@ -588,7 +588,7 @@ static int http_stream_read_response(
588588
(error = handle_response(&complete, stream, &response, false)) < 0)
589589
goto done;
590590

591-
assert(complete);
591+
GIT_ASSERT(complete);
592592
stream->state = HTTP_STATE_RECEIVING_RESPONSE;
593593
}
594594

@@ -637,7 +637,8 @@ static int http_action(
637637
const http_service *service;
638638
int error;
639639

640-
assert(out && t);
640+
GIT_ASSERT_ARG(out);
641+
GIT_ASSERT_ARG(t);
641642

642643
*out = NULL;
643644

@@ -720,7 +721,7 @@ int git_smart_subtransport_http(git_smart_subtransport **out, git_transport *own
720721

721722
GIT_UNUSED(param);
722723

723-
assert(out);
724+
GIT_ASSERT_ARG(out);
724725

725726
transport = git__calloc(sizeof(http_subtransport), 1);
726727
GIT_ERROR_CHECK_ALLOC(transport);

src/transports/httpclient.c

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,8 @@ bool git_http_response_is_redirect(git_http_response *response)
145145

146146
void git_http_response_dispose(git_http_response *response)
147147
{
148-
assert(response);
148+
if (!response)
149+
return;
149150

150151
git__free(response->content_type);
151152
git__free(response->location);
@@ -399,7 +400,7 @@ static int on_body(http_parser *parser, const char *buf, size_t len)
399400
return 0;
400401
}
401402

402-
assert(ctx->output_size >= ctx->output_written);
403+
GIT_ASSERT(ctx->output_size >= ctx->output_written);
403404

404405
max_len = min(ctx->output_size - ctx->output_written, len);
405406
max_len = min(max_len, INT_MAX);
@@ -665,7 +666,8 @@ static int generate_request(
665666
size_t i;
666667
int error;
667668

668-
assert(client && request);
669+
GIT_ASSERT_ARG(client);
670+
GIT_ASSERT_ARG(request);
669671

670672
git_buf_clear(&client->request_msg);
671673
buf = &client->request_msg;
@@ -842,7 +844,10 @@ static int setup_hosts(
842844
{
843845
int ret, diff = 0;
844846

845-
assert(client && request && request->url);
847+
GIT_ASSERT_ARG(client);
848+
GIT_ASSERT_ARG(request);
849+
850+
GIT_ASSERT(request->url);
846851

847852
if ((ret = server_setup_from_url(&client->server, request->url)) < 0)
848853
return ret;
@@ -922,7 +927,7 @@ static int proxy_connect(
922927
(error = git_http_client_skip_body(client)) < 0)
923928
goto done;
924929

925-
assert(client->state == DONE);
930+
GIT_ASSERT(client->state == DONE);
926931

927932
if (response.status == GIT_HTTP_STATUS_PROXY_AUTHENTICATION_REQUIRED) {
928933
save_early_response(client, &response);
@@ -1137,7 +1142,7 @@ GIT_INLINE(int) client_read_and_parse(git_http_client *client)
11371142
* final byte when paused in a callback. Consume that byte.
11381143
* https://github.com/nodejs/http-parser/issues/97
11391144
*/
1140-
assert(client->read_buf.size > parsed_len);
1145+
GIT_ASSERT(client->read_buf.size > parsed_len);
11411146

11421147
http_parser_pause(parser, 0);
11431148

@@ -1215,7 +1220,8 @@ int git_http_client_send_request(
12151220
git_http_response response = {0};
12161221
int error = -1;
12171222

1218-
assert(client && request);
1223+
GIT_ASSERT_ARG(client);
1224+
GIT_ASSERT_ARG(request);
12191225

12201226
/* If the client did not finish reading, clean up the stream. */
12211227
if (client->state == READING_BODY)
@@ -1286,7 +1292,7 @@ int git_http_client_send_body(
12861292
git_buf hdr = GIT_BUF_INIT;
12871293
int error;
12881294

1289-
assert(client);
1295+
GIT_ASSERT_ARG(client);
12901296

12911297
/* If we're waiting for proxy auth, don't sending more requests. */
12921298
if (client->state == HAS_EARLY_RESPONSE)
@@ -1303,7 +1309,7 @@ int git_http_client_send_body(
13031309
server = &client->server;
13041310

13051311
if (client->request_body_len) {
1306-
assert(buffer_len <= client->request_body_remain);
1312+
GIT_ASSERT(buffer_len <= client->request_body_remain);
13071313

13081314
if ((error = stream_write(server, buffer, buffer_len)) < 0)
13091315
goto done;
@@ -1326,7 +1332,8 @@ static int complete_request(git_http_client *client)
13261332
{
13271333
int error = 0;
13281334

1329-
assert(client && client->state == SENDING_BODY);
1335+
GIT_ASSERT_ARG(client);
1336+
GIT_ASSERT(client->state == SENDING_BODY);
13301337

13311338
if (client->request_body_len && client->request_body_remain) {
13321339
git_error_set(GIT_ERROR_HTTP, "truncated write");
@@ -1346,7 +1353,8 @@ int git_http_client_read_response(
13461353
http_parser_context parser_context = {0};
13471354
int error;
13481355

1349-
assert(response && client);
1356+
GIT_ASSERT_ARG(response);
1357+
GIT_ASSERT_ARG(client);
13501358

13511359
if (client->state == SENDING_BODY) {
13521360
if ((error = complete_request(client)) < 0)
@@ -1386,7 +1394,7 @@ int git_http_client_read_response(
13861394
goto done;
13871395
}
13881396

1389-
assert(client->state == READING_BODY || client->state == DONE);
1397+
GIT_ASSERT(client->state == READING_BODY || client->state == DONE);
13901398

13911399
done:
13921400
git_buf_dispose(&parser_context.parse_header_name);
@@ -1439,7 +1447,7 @@ int git_http_client_read_body(
14391447
break;
14401448
}
14411449

1442-
assert(parser_context.output_written <= INT_MAX);
1450+
GIT_ASSERT(parser_context.output_written <= INT_MAX);
14431451
error = (int)parser_context.output_written;
14441452

14451453
done:
@@ -1493,7 +1501,7 @@ int git_http_client_new(
14931501
{
14941502
git_http_client *client;
14951503

1496-
assert(out);
1504+
GIT_ASSERT_ARG(out);
14971505

14981506
client = git__calloc(1, sizeof(git_http_client));
14991507
GIT_ERROR_CHECK_ALLOC(client);

src/transports/local.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ static int store_refs(transport_local *t)
158158
git_remote_head *head;
159159
git_strarray ref_names = {0};
160160

161-
assert(t);
161+
GIT_ASSERT_ARG(t);
162162

163163
if (git_reference_list(&ref_names, t->repo) < 0)
164164
goto on_error;

src/transports/smart.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ static int git_smart__recv_cb(gitno_buffer *buf)
1818
size_t old_len, bytes_read;
1919
int error;
2020

21-
assert(t->current_stream);
21+
GIT_ASSERT(t->current_stream);
2222

2323
old_len = buf->offset;
2424

@@ -346,7 +346,7 @@ int git_smart__negotiation_step(git_transport *transport, void *data, size_t len
346346
return error;
347347

348348
/* If this is a stateful implementation, the stream we get back should be the same */
349-
assert(t->rpc || t->current_stream == stream);
349+
GIT_ASSERT(t->rpc || t->current_stream == stream);
350350

351351
/* Save off the current stream (i.e. socket) that we are working with */
352352
t->current_stream = stream;
@@ -375,7 +375,7 @@ int git_smart__get_push_stream(transport_smart *t, git_smart_subtransport_stream
375375
return error;
376376

377377
/* If this is a stateful implementation, the stream we get back should be the same */
378-
assert(t->rpc || t->current_stream == *stream);
378+
GIT_ASSERT(t->rpc || t->current_stream == *stream);
379379

380380
/* Save off the current stream (i.e. socket) that we are working with */
381381
t->current_stream = *stream;
@@ -481,7 +481,9 @@ int git_transport_smart_certificate_check(git_transport *transport, git_cert *ce
481481
{
482482
transport_smart *t = GIT_CONTAINER_OF(transport, transport_smart, parent);
483483

484-
assert(transport && cert && hostname);
484+
GIT_ASSERT_ARG(transport);
485+
GIT_ASSERT_ARG(cert);
486+
GIT_ASSERT_ARG(hostname);
485487

486488
if (!t->certificate_check_cb)
487489
return GIT_PASSTHROUGH;
@@ -493,7 +495,8 @@ int git_transport_smart_credentials(git_credential **out, git_transport *transpo
493495
{
494496
transport_smart *t = GIT_CONTAINER_OF(transport, transport_smart, parent);
495497

496-
assert(out && transport);
498+
GIT_ASSERT_ARG(out);
499+
GIT_ASSERT_ARG(transport);
497500

498501
if (!t->cred_acquire_cb)
499502
return GIT_PASSTHROUGH;

0 commit comments

Comments
 (0)