transports: 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 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577
diff --git a/src/transports/auth_negotiate.c b/src/transports/auth_negotiate.c
index 8a614b8..c538dbb 100644
--- a/src/transports/auth_negotiate.c
+++ b/src/transports/auth_negotiate.c
@@ -65,7 +65,9 @@ static int negotiate_set_challenge(
{
http_auth_negotiate_context *ctx = (http_auth_negotiate_context *)c;
- assert(ctx && ctx->configured && challenge);
+ GIT_ASSERT_ARG(ctx);
+ GIT_ASSERT_ARG(challenge);
+ GIT_ASSERT(ctx->configured);
git__free(ctx->challenge);
@@ -108,7 +110,12 @@ static int negotiate_next_token(
size_t challenge_len;
int error = 0;
- assert(buf && ctx && ctx->configured && cred && cred->credtype == GIT_CREDENTIAL_DEFAULT);
+ GIT_ASSERT_ARG(buf);
+ GIT_ASSERT_ARG(ctx);
+ GIT_ASSERT_ARG(cred);
+
+ GIT_ASSERT(ctx->configured);
+ GIT_ASSERT(cred->credtype == GIT_CREDENTIAL_DEFAULT);
if (ctx->complete)
return 0;
@@ -202,7 +209,7 @@ static int negotiate_is_complete(git_http_auth_context *c)
{
http_auth_negotiate_context *ctx = (http_auth_negotiate_context *)c;
- assert(ctx);
+ GIT_ASSERT_ARG(ctx);
return (ctx->complete == 1);
}
diff --git a/src/transports/auth_ntlm.c b/src/transports/auth_ntlm.c
index d134a3d..e0960bf 100644
--- a/src/transports/auth_ntlm.c
+++ b/src/transports/auth_ntlm.c
@@ -29,7 +29,8 @@ static int ntlm_set_challenge(
{
http_auth_ntlm_context *ctx = (http_auth_ntlm_context *)c;
- assert(ctx && challenge);
+ GIT_ASSERT_ARG(ctx);
+ GIT_ASSERT_ARG(challenge);
git__free(ctx->challenge);
@@ -46,7 +47,7 @@ static int ntlm_set_credentials(http_auth_ntlm_context *ctx, git_credential *_cr
char *domain = NULL, *domainuser = NULL;
int error = 0;
- assert(_cred->credtype == GIT_CREDENTIAL_USERPASS_PLAINTEXT);
+ GIT_ASSERT(_cred->credtype == GIT_CREDENTIAL_USERPASS_PLAINTEXT);
cred = (git_credential_userpass_plaintext *)_cred;
if ((sep = strchr(cred->username, '\\')) != NULL) {
@@ -86,7 +87,10 @@ static int ntlm_next_token(
size_t challenge_len, msg_len;
int error = -1;
- assert(buf && ctx && ctx->ntlm);
+ GIT_ASSERT_ARG(buf);
+ GIT_ASSERT_ARG(ctx);
+
+ GIT_ASSERT(ctx->ntlm);
challenge_len = ctx->challenge ? strlen(ctx->challenge) : 0;
@@ -162,7 +166,7 @@ static int ntlm_is_complete(git_http_auth_context *c)
{
http_auth_ntlm_context *ctx = (http_auth_ntlm_context *)c;
- assert(ctx);
+ GIT_ASSERT_ARG(ctx);
return (ctx->complete == true);
}
diff --git a/src/transports/credential.c b/src/transports/credential.c
index 7b28364..6e00b02 100644
--- a/src/transports/credential.c
+++ b/src/transports/credential.c
@@ -85,7 +85,9 @@ int git_credential_userpass_plaintext_new(
{
git_credential_userpass_plaintext *c;
- assert(cred && username && password);
+ GIT_ASSERT_ARG(cred);
+ GIT_ASSERT_ARG(username);
+ GIT_ASSERT_ARG(password);
c = git__malloc(sizeof(git_credential_userpass_plaintext));
GIT_ERROR_CHECK_ALLOC(c);
@@ -233,7 +235,9 @@ static int git_credential_ssh_key_type_new(
{
git_credential_ssh_key *c;
- assert(username && cred && privatekey);
+ GIT_ASSERT_ARG(username);
+ GIT_ASSERT_ARG(cred);
+ GIT_ASSERT_ARG(privatekey);
c = git__calloc(1, sizeof(git_credential_ssh_key));
GIT_ERROR_CHECK_ALLOC(c);
@@ -269,7 +273,9 @@ int git_credential_ssh_interactive_new(
{
git_credential_ssh_interactive *c;
- assert(out && username && prompt_callback);
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(username);
+ GIT_ASSERT_ARG(prompt_callback);
c = git__calloc(1, sizeof(git_credential_ssh_interactive));
GIT_ERROR_CHECK_ALLOC(c);
@@ -290,7 +296,8 @@ int git_credential_ssh_interactive_new(
int git_credential_ssh_key_from_agent(git_credential **cred, const char *username) {
git_credential_ssh_key *c;
- assert(username && cred);
+ GIT_ASSERT_ARG(username);
+ GIT_ASSERT_ARG(cred);
c = git__calloc(1, sizeof(git_credential_ssh_key));
GIT_ERROR_CHECK_ALLOC(c);
@@ -317,7 +324,8 @@ int git_credential_ssh_custom_new(
{
git_credential_ssh_custom *c;
- assert(username && cred);
+ GIT_ASSERT_ARG(username);
+ GIT_ASSERT_ARG(cred);
c = git__calloc(1, sizeof(git_credential_ssh_custom));
GIT_ERROR_CHECK_ALLOC(c);
@@ -347,7 +355,7 @@ int git_credential_default_new(git_credential **cred)
{
git_credential_default *c;
- assert(cred);
+ GIT_ASSERT_ARG(cred);
c = git__calloc(1, sizeof(git_credential_default));
GIT_ERROR_CHECK_ALLOC(c);
@@ -364,7 +372,7 @@ int git_credential_username_new(git_credential **cred, const char *username)
git_credential_username *c;
size_t len, allocsize;
- assert(cred);
+ GIT_ASSERT_ARG(cred);
len = strlen(username);
diff --git a/src/transports/git.c b/src/transports/git.c
index e48b7f9..7c93155 100644
--- a/src/transports/git.c
+++ b/src/transports/git.c
@@ -327,7 +327,7 @@ static int _git_close(git_smart_subtransport *subtransport)
{
git_subtransport *t = (git_subtransport *) subtransport;
- assert(!t->current_stream);
+ GIT_ASSERT(!t->current_stream);
GIT_UNUSED(t);
@@ -338,8 +338,6 @@ static void _git_free(git_smart_subtransport *subtransport)
{
git_subtransport *t = (git_subtransport *) subtransport;
- assert(!t->current_stream);
-
git__free(t);
}
diff --git a/src/transports/http.c b/src/transports/http.c
index fb1740c..4538dd1 100644
--- a/src/transports/http.c
+++ b/src/transports/http.c
@@ -416,7 +416,7 @@ static int http_stream_read(
goto done;
}
- assert (stream->state == HTTP_STATE_RECEIVING_RESPONSE);
+ GIT_ASSERT(stream->state == HTTP_STATE_RECEIVING_RESPONSE);
error = git_http_client_read_body(transport->http_client, buffer, buffer_size);
@@ -554,7 +554,7 @@ static int http_stream_write(
goto done;
}
- assert(stream->state == HTTP_STATE_SENDING_REQUEST);
+ GIT_ASSERT(stream->state == HTTP_STATE_SENDING_REQUEST);
error = git_http_client_send_body(transport->http_client, buffer, len);
@@ -588,7 +588,7 @@ static int http_stream_read_response(
(error = handle_response(&complete, stream, &response, false)) < 0)
goto done;
- assert(complete);
+ GIT_ASSERT(complete);
stream->state = HTTP_STATE_RECEIVING_RESPONSE;
}
@@ -637,7 +637,8 @@ static int http_action(
const http_service *service;
int error;
- assert(out && t);
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(t);
*out = NULL;
@@ -720,7 +721,7 @@ int git_smart_subtransport_http(git_smart_subtransport **out, git_transport *own
GIT_UNUSED(param);
- assert(out);
+ GIT_ASSERT_ARG(out);
transport = git__calloc(sizeof(http_subtransport), 1);
GIT_ERROR_CHECK_ALLOC(transport);
diff --git a/src/transports/httpclient.c b/src/transports/httpclient.c
index 6ec22f8..d9cbf17 100644
--- a/src/transports/httpclient.c
+++ b/src/transports/httpclient.c
@@ -145,7 +145,8 @@ bool git_http_response_is_redirect(git_http_response *response)
void git_http_response_dispose(git_http_response *response)
{
- assert(response);
+ if (!response)
+ return;
git__free(response->content_type);
git__free(response->location);
@@ -399,7 +400,7 @@ static int on_body(http_parser *parser, const char *buf, size_t len)
return 0;
}
- assert(ctx->output_size >= ctx->output_written);
+ GIT_ASSERT(ctx->output_size >= ctx->output_written);
max_len = min(ctx->output_size - ctx->output_written, len);
max_len = min(max_len, INT_MAX);
@@ -665,7 +666,8 @@ static int generate_request(
size_t i;
int error;
- assert(client && request);
+ GIT_ASSERT_ARG(client);
+ GIT_ASSERT_ARG(request);
git_buf_clear(&client->request_msg);
buf = &client->request_msg;
@@ -842,7 +844,10 @@ static int setup_hosts(
{
int ret, diff = 0;
- assert(client && request && request->url);
+ GIT_ASSERT_ARG(client);
+ GIT_ASSERT_ARG(request);
+
+ GIT_ASSERT(request->url);
if ((ret = server_setup_from_url(&client->server, request->url)) < 0)
return ret;
@@ -922,7 +927,7 @@ static int proxy_connect(
(error = git_http_client_skip_body(client)) < 0)
goto done;
- assert(client->state == DONE);
+ GIT_ASSERT(client->state == DONE);
if (response.status == GIT_HTTP_STATUS_PROXY_AUTHENTICATION_REQUIRED) {
save_early_response(client, &response);
@@ -1137,7 +1142,7 @@ GIT_INLINE(int) client_read_and_parse(git_http_client *client)
* final byte when paused in a callback. Consume that byte.
* https://github.com/nodejs/http-parser/issues/97
*/
- assert(client->read_buf.size > parsed_len);
+ GIT_ASSERT(client->read_buf.size > parsed_len);
http_parser_pause(parser, 0);
@@ -1215,7 +1220,8 @@ int git_http_client_send_request(
git_http_response response = {0};
int error = -1;
- assert(client && request);
+ GIT_ASSERT_ARG(client);
+ GIT_ASSERT_ARG(request);
/* If the client did not finish reading, clean up the stream. */
if (client->state == READING_BODY)
@@ -1286,7 +1292,7 @@ int git_http_client_send_body(
git_buf hdr = GIT_BUF_INIT;
int error;
- assert(client);
+ GIT_ASSERT_ARG(client);
/* If we're waiting for proxy auth, don't sending more requests. */
if (client->state == HAS_EARLY_RESPONSE)
@@ -1303,7 +1309,7 @@ int git_http_client_send_body(
server = &client->server;
if (client->request_body_len) {
- assert(buffer_len <= client->request_body_remain);
+ GIT_ASSERT(buffer_len <= client->request_body_remain);
if ((error = stream_write(server, buffer, buffer_len)) < 0)
goto done;
@@ -1326,7 +1332,8 @@ static int complete_request(git_http_client *client)
{
int error = 0;
- assert(client && client->state == SENDING_BODY);
+ GIT_ASSERT_ARG(client);
+ GIT_ASSERT(client->state == SENDING_BODY);
if (client->request_body_len && client->request_body_remain) {
git_error_set(GIT_ERROR_HTTP, "truncated write");
@@ -1346,7 +1353,8 @@ int git_http_client_read_response(
http_parser_context parser_context = {0};
int error;
- assert(response && client);
+ GIT_ASSERT_ARG(response);
+ GIT_ASSERT_ARG(client);
if (client->state == SENDING_BODY) {
if ((error = complete_request(client)) < 0)
@@ -1386,7 +1394,7 @@ int git_http_client_read_response(
goto done;
}
- assert(client->state == READING_BODY || client->state == DONE);
+ GIT_ASSERT(client->state == READING_BODY || client->state == DONE);
done:
git_buf_dispose(&parser_context.parse_header_name);
@@ -1439,7 +1447,7 @@ int git_http_client_read_body(
break;
}
- assert(parser_context.output_written <= INT_MAX);
+ GIT_ASSERT(parser_context.output_written <= INT_MAX);
error = (int)parser_context.output_written;
done:
@@ -1493,7 +1501,7 @@ int git_http_client_new(
{
git_http_client *client;
- assert(out);
+ GIT_ASSERT_ARG(out);
client = git__calloc(1, sizeof(git_http_client));
GIT_ERROR_CHECK_ALLOC(client);
diff --git a/src/transports/local.c b/src/transports/local.c
index 210de9f..4af85db 100644
--- a/src/transports/local.c
+++ b/src/transports/local.c
@@ -158,7 +158,7 @@ static int store_refs(transport_local *t)
git_remote_head *head;
git_strarray ref_names = {0};
- assert(t);
+ GIT_ASSERT_ARG(t);
if (git_reference_list(&ref_names, t->repo) < 0)
goto on_error;
diff --git a/src/transports/smart.c b/src/transports/smart.c
index 5f59194..3b8a14a 100644
--- a/src/transports/smart.c
+++ b/src/transports/smart.c
@@ -18,7 +18,7 @@ static int git_smart__recv_cb(gitno_buffer *buf)
size_t old_len, bytes_read;
int error;
- assert(t->current_stream);
+ GIT_ASSERT(t->current_stream);
old_len = buf->offset;
@@ -346,7 +346,7 @@ int git_smart__negotiation_step(git_transport *transport, void *data, size_t len
return error;
/* If this is a stateful implementation, the stream we get back should be the same */
- assert(t->rpc || t->current_stream == stream);
+ GIT_ASSERT(t->rpc || t->current_stream == stream);
/* Save off the current stream (i.e. socket) that we are working with */
t->current_stream = stream;
@@ -375,7 +375,7 @@ int git_smart__get_push_stream(transport_smart *t, git_smart_subtransport_stream
return error;
/* If this is a stateful implementation, the stream we get back should be the same */
- assert(t->rpc || t->current_stream == *stream);
+ GIT_ASSERT(t->rpc || t->current_stream == *stream);
/* Save off the current stream (i.e. socket) that we are working with */
t->current_stream = *stream;
@@ -481,7 +481,9 @@ int git_transport_smart_certificate_check(git_transport *transport, git_cert *ce
{
transport_smart *t = GIT_CONTAINER_OF(transport, transport_smart, parent);
- assert(transport && cert && hostname);
+ GIT_ASSERT_ARG(transport);
+ GIT_ASSERT_ARG(cert);
+ GIT_ASSERT_ARG(hostname);
if (!t->certificate_check_cb)
return GIT_PASSTHROUGH;
@@ -493,7 +495,8 @@ int git_transport_smart_credentials(git_credential **out, git_transport *transpo
{
transport_smart *t = GIT_CONTAINER_OF(transport, transport_smart, parent);
- assert(out && transport);
+ GIT_ASSERT_ARG(out);
+ GIT_ASSERT_ARG(transport);
if (!t->cred_acquire_cb)
return GIT_PASSTHROUGH;
diff --git a/src/transports/ssh.c b/src/transports/ssh.c
index f4ed05b..b7efd5c 100644
--- a/src/transports/ssh.c
+++ b/src/transports/ssh.c
@@ -238,7 +238,7 @@ static int ssh_stream_alloc(
{
ssh_stream *s;
- assert(stream);
+ GIT_ASSERT_ARG(stream);
s = git__calloc(sizeof(ssh_stream), 1);
GIT_ERROR_CHECK_ALLOC(s);
@@ -404,8 +404,8 @@ static int _git_ssh_authenticate_session(
case GIT_CREDENTIAL_SSH_MEMORY: {
git_credential_ssh_key *c = (git_credential_ssh_key *)cred;
- assert(c->username);
- assert(c->privatekey);
+ GIT_ASSERT(c->username);
+ GIT_ASSERT(c->privatekey);
rc = libssh2_userauth_publickey_frommemory(
session,
@@ -483,7 +483,7 @@ static int _git_ssh_session_create(
LIBSSH2_SESSION* s;
git_socket_stream *socket = GIT_CONTAINER_OF(io, git_socket_stream, parent);
- assert(session);
+ GIT_ASSERT_ARG(session);
s = libssh2_session_init();
if (!s) {
@@ -772,7 +772,7 @@ static int _ssh_close(git_smart_subtransport *subtransport)
{
ssh_subtransport *t = GIT_CONTAINER_OF(subtransport, ssh_subtransport, parent);
- assert(!t->current_stream);
+ GIT_ASSERT(!t->current_stream);
GIT_UNUSED(t);
@@ -783,8 +783,6 @@ static void _ssh_free(git_smart_subtransport *subtransport)
{
ssh_subtransport *t = GIT_CONTAINER_OF(subtransport, ssh_subtransport, parent);
- assert(!t->current_stream);
-
git__free(t->cmd_uploadpack);
git__free(t->cmd_receivepack);
git__free(t);
@@ -849,7 +847,7 @@ int git_smart_subtransport_ssh(
#ifdef GIT_SSH
ssh_subtransport *t;
- assert(out);
+ GIT_ASSERT_ARG(out);
GIT_UNUSED(param);
@@ -867,7 +865,7 @@ int git_smart_subtransport_ssh(
GIT_UNUSED(owner);
GIT_UNUSED(param);
- assert(out);
+ GIT_ASSERT_ARG(out);
*out = NULL;
git_error_set(GIT_ERROR_INVALID, "cannot create SSH transport. Library was built without SSH support");
@@ -911,7 +909,7 @@ int git_transport_ssh_with_paths(git_transport **out, git_remote *owner, void *p
GIT_UNUSED(owner);
GIT_UNUSED(payload);
- assert(out);
+ GIT_ASSERT_ARG(out);
*out = NULL;
git_error_set(GIT_ERROR_INVALID, "cannot create SSH transport. Library was built without SSH support");
diff --git a/src/transports/winhttp.c b/src/transports/winhttp.c
index 2a1f6f2..2b77ec9 100644
--- a/src/transports/winhttp.c
+++ b/src/transports/winhttp.c
@@ -1003,7 +1003,7 @@ replay:
}
if (s->chunked) {
- assert(s->verb == post_verb);
+ GIT_ASSERT(s->verb == post_verb);
/* Flush, if necessary */
if (s->chunk_buffer_len > 0 &&
@@ -1054,7 +1054,7 @@ replay:
}
len -= bytes_read;
- assert(bytes_read == bytes_written);
+ GIT_ASSERT(bytes_read == bytes_written);
}
git__free(buffer);
@@ -1166,7 +1166,7 @@ replay:
if (error < 0) {
return error;
} else if (!error) {
- assert(t->server.cred);
+ GIT_ASSERT(t->server.cred);
winhttp_stream_close(s);
goto replay;
}
@@ -1180,7 +1180,7 @@ replay:
if (error < 0) {
return error;
} else if (!error) {
- assert(t->proxy.cred);
+ GIT_ASSERT(t->proxy.cred);
winhttp_stream_close(s);
goto replay;
}
@@ -1266,7 +1266,7 @@ static int winhttp_stream_write_single(
return -1;
}
- assert((DWORD)len == bytes_written);
+ GIT_ASSERT((DWORD)len == bytes_written);
return 0;
}
@@ -1365,7 +1365,7 @@ static int winhttp_stream_write_buffered(
return -1;
}
- assert((DWORD)len == bytes_written);
+ GIT_ASSERT((DWORD)len == bytes_written);
s->post_body_len += bytes_written;
@@ -1572,7 +1572,7 @@ static int winhttp_action(
break;
default:
- assert(0);
+ GIT_ASSERT(0);
}
if (!ret)