Commit 4f5f1127 by Edward Thomson

transports: use GIT_ASSERT

parent 07a3c992
......@@ -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);
}
......
......@@ -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);
}
......
......@@ -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);
......
......@@ -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);
}
......
......@@ -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);
......
......@@ -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);
......
......@@ -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;
......
......@@ -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;
......
......@@ -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");
......
......@@ -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)
......
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