diff options
author | Noah Eisen <ncteisen@google.com> | 2018-02-09 09:16:55 -0800 |
---|---|---|
committer | Noah Eisen <ncteisen@google.com> | 2018-02-09 09:16:55 -0800 |
commit | be82e64b3debcdb1d9ec6a149fc85af0d46bfb7e (patch) | |
tree | cc5e1234073eb250a2c319b5a4db2919fce060ea /src/core/tsi | |
parent | 194436342137924b4fb7429bede037a4b5ec7edb (diff) |
Autofix c casts to c++ casts
Diffstat (limited to 'src/core/tsi')
-rw-r--r-- | src/core/tsi/fake_transport_security.cc | 82 | ||||
-rw-r--r-- | src/core/tsi/ssl_transport_security.cc | 144 | ||||
-rw-r--r-- | src/core/tsi/transport_security.cc | 6 | ||||
-rw-r--r-- | src/core/tsi/transport_security_adapter.cc | 20 |
4 files changed, 126 insertions, 126 deletions
diff --git a/src/core/tsi/fake_transport_security.cc b/src/core/tsi/fake_transport_security.cc index 7d5aaa7305..c7eb750a5b 100644 --- a/src/core/tsi/fake_transport_security.cc +++ b/src/core/tsi/fake_transport_security.cc @@ -102,7 +102,7 @@ static tsi_result tsi_fake_handshake_message_from_string( for (int i = 0; i < TSI_FAKE_HANDSHAKE_MESSAGE_MAX; i++) { if (strncmp(msg_string, tsi_fake_handshake_message_strings[i], strlen(tsi_fake_handshake_message_strings[i])) == 0) { - *msg = (tsi_fake_handshake_message)i; + *msg = static_cast<tsi_fake_handshake_message>(i); return TSI_OK; } } @@ -111,15 +111,15 @@ static tsi_result tsi_fake_handshake_message_from_string( } static uint32_t load32_little_endian(const unsigned char* buf) { - return ((uint32_t)(buf[0]) | (uint32_t)(buf[1] << 8) | - (uint32_t)(buf[2] << 16) | (uint32_t)(buf[3] << 24)); + return (static_cast<uint32_t>(buf[0]) | static_cast<uint32_t>(buf[1] << 8) | + static_cast<uint32_t>(buf[2] << 16) | static_cast<uint32_t>(buf[3] << 24)); } static void store32_little_endian(uint32_t value, unsigned char* buf) { - buf[3] = (unsigned char)((value >> 24) & 0xFF); - buf[2] = (unsigned char)((value >> 16) & 0xFF); - buf[1] = (unsigned char)((value >> 8) & 0xFF); - buf[0] = (unsigned char)((value)&0xFF); + buf[3] = static_cast<unsigned char>((value >> 24) & 0xFF); + buf[2] = static_cast<unsigned char>((value >> 16) & 0xFF); + buf[1] = static_cast<unsigned char>((value >> 8) & 0xFF); + buf[0] = static_cast<unsigned char>((value)&0xFF); } static uint32_t read_frame_size(const grpc_slice_buffer* sb) { @@ -155,10 +155,10 @@ static void tsi_fake_frame_reset(tsi_fake_frame* frame, int needs_draining) { static void tsi_fake_frame_ensure_size(tsi_fake_frame* frame) { if (frame->data == nullptr) { frame->allocated_size = frame->size; - frame->data = (unsigned char*)gpr_malloc(frame->allocated_size); + frame->data = static_cast<unsigned char*>(gpr_malloc(frame->allocated_size)); } else if (frame->size > frame->allocated_size) { unsigned char* new_data = - (unsigned char*)gpr_realloc(frame->data, frame->size); + static_cast<unsigned char*>(gpr_realloc(frame->data, frame->size)); frame->data = new_data; frame->allocated_size = frame->size; } @@ -177,7 +177,7 @@ static tsi_result tsi_fake_frame_decode(const unsigned char* incoming_bytes, if (frame->needs_draining) return TSI_INTERNAL_ERROR; if (frame->data == nullptr) { frame->allocated_size = TSI_FAKE_FRAME_INITIAL_ALLOCATED_SIZE; - frame->data = (unsigned char*)gpr_malloc(frame->allocated_size); + frame->data = static_cast<unsigned char*>(gpr_malloc(frame->allocated_size)); } if (frame->offset < TSI_FAKE_FRAME_HEADER_SIZE) { @@ -187,7 +187,7 @@ static tsi_result tsi_fake_frame_decode(const unsigned char* incoming_bytes, memcpy(frame->data + frame->offset, bytes_cursor, available_size); bytes_cursor += available_size; frame->offset += available_size; - *incoming_bytes_size = (size_t)(bytes_cursor - incoming_bytes); + *incoming_bytes_size = static_cast<size_t>(bytes_cursor - incoming_bytes); return TSI_INCOMPLETE_DATA; } memcpy(frame->data + frame->offset, bytes_cursor, to_read_size); @@ -203,12 +203,12 @@ static tsi_result tsi_fake_frame_decode(const unsigned char* incoming_bytes, memcpy(frame->data + frame->offset, bytes_cursor, available_size); frame->offset += available_size; bytes_cursor += available_size; - *incoming_bytes_size = (size_t)(bytes_cursor - incoming_bytes); + *incoming_bytes_size = static_cast<size_t>(bytes_cursor - incoming_bytes); return TSI_INCOMPLETE_DATA; } memcpy(frame->data + frame->offset, bytes_cursor, to_read_size); bytes_cursor += to_read_size; - *incoming_bytes_size = (size_t)(bytes_cursor - incoming_bytes); + *incoming_bytes_size = static_cast<size_t>(bytes_cursor - incoming_bytes); tsi_fake_frame_reset(frame, 1 /* needs_draining */); return TSI_OK; } @@ -239,7 +239,7 @@ static tsi_result tsi_fake_frame_set_data(unsigned char* data, size_t data_size, frame->offset = 0; frame->size = data_size + TSI_FAKE_FRAME_HEADER_SIZE; tsi_fake_frame_ensure_size(frame); - store32_little_endian((uint32_t)frame->size, frame->data); + store32_little_endian(static_cast<uint32_t>(frame->size), frame->data); memcpy(frame->data + TSI_FAKE_FRAME_HEADER_SIZE, data, data_size); tsi_fake_frame_reset(frame, 1 /* needs draining */); return TSI_OK; @@ -258,7 +258,7 @@ static tsi_result fake_protector_protect(tsi_frame_protector* self, unsigned char* protected_output_frames, size_t* protected_output_frames_size) { tsi_result result = TSI_OK; - tsi_fake_frame_protector* impl = (tsi_fake_frame_protector*)self; + tsi_fake_frame_protector* impl = reinterpret_cast<tsi_fake_frame_protector*>(self); unsigned char frame_header[TSI_FAKE_FRAME_HEADER_SIZE]; tsi_fake_frame* frame = &impl->protect_frame; size_t saved_output_size = *protected_output_frames_size; @@ -287,7 +287,7 @@ static tsi_result fake_protector_protect(tsi_frame_protector* self, if (frame->size == 0) { /* New frame, create a header. */ size_t written_in_frame_size = 0; - store32_little_endian((uint32_t)impl->max_frame_size, frame_header); + store32_little_endian(static_cast<uint32_t>(impl->max_frame_size), frame_header); written_in_frame_size = TSI_FAKE_FRAME_HEADER_SIZE; result = tsi_fake_frame_decode(frame_header, &written_in_frame_size, frame); if (result != TSI_INCOMPLETE_DATA) { @@ -317,14 +317,14 @@ static tsi_result fake_protector_protect_flush( tsi_frame_protector* self, unsigned char* protected_output_frames, size_t* protected_output_frames_size, size_t* still_pending_size) { tsi_result result = TSI_OK; - tsi_fake_frame_protector* impl = (tsi_fake_frame_protector*)self; + tsi_fake_frame_protector* impl = reinterpret_cast<tsi_fake_frame_protector*>(self); tsi_fake_frame* frame = &impl->protect_frame; if (!frame->needs_draining) { /* Create a short frame. */ frame->size = frame->offset; frame->offset = 0; frame->needs_draining = 1; - store32_little_endian((uint32_t)frame->size, + store32_little_endian(static_cast<uint32_t>(frame->size), frame->data); /* Overwrite header. */ } result = tsi_fake_frame_encode(protected_output_frames, @@ -339,7 +339,7 @@ static tsi_result fake_protector_unprotect( size_t* protected_frames_bytes_size, unsigned char* unprotected_bytes, size_t* unprotected_bytes_size) { tsi_result result = TSI_OK; - tsi_fake_frame_protector* impl = (tsi_fake_frame_protector*)self; + tsi_fake_frame_protector* impl = reinterpret_cast<tsi_fake_frame_protector*>(self); tsi_fake_frame* frame = &impl->unprotect_frame; size_t saved_output_size = *unprotected_bytes_size; size_t drained_size = 0; @@ -384,7 +384,7 @@ static tsi_result fake_protector_unprotect( } static void fake_protector_destroy(tsi_frame_protector* self) { - tsi_fake_frame_protector* impl = (tsi_fake_frame_protector*)self; + tsi_fake_frame_protector* impl = reinterpret_cast<tsi_fake_frame_protector*>(self); tsi_fake_frame_destruct(&impl->protect_frame); tsi_fake_frame_destruct(&impl->unprotect_frame); gpr_free(self); @@ -407,14 +407,14 @@ static tsi_result fake_zero_copy_grpc_protector_protect( return TSI_INVALID_ARGUMENT; } tsi_fake_zero_copy_grpc_protector* impl = - (tsi_fake_zero_copy_grpc_protector*)self; + reinterpret_cast<tsi_fake_zero_copy_grpc_protector*>(self); /* Protects each frame. */ while (unprotected_slices->length > 0) { size_t frame_length = GPR_MIN(impl->max_frame_size, unprotected_slices->length + TSI_FAKE_FRAME_HEADER_SIZE); grpc_slice slice = GRPC_SLICE_MALLOC(TSI_FAKE_FRAME_HEADER_SIZE); - store32_little_endian((uint32_t)frame_length, GRPC_SLICE_START_PTR(slice)); + store32_little_endian(static_cast<uint32_t>(frame_length), GRPC_SLICE_START_PTR(slice)); grpc_slice_buffer_add(protected_slices, slice); size_t data_length = frame_length - TSI_FAKE_FRAME_HEADER_SIZE; grpc_slice_buffer_move_first(unprotected_slices, data_length, @@ -431,7 +431,7 @@ static tsi_result fake_zero_copy_grpc_protector_unprotect( return TSI_INVALID_ARGUMENT; } tsi_fake_zero_copy_grpc_protector* impl = - (tsi_fake_zero_copy_grpc_protector*)self; + reinterpret_cast<tsi_fake_zero_copy_grpc_protector*>(self); grpc_slice_buffer_move_into(protected_slices, &impl->protected_sb); /* Unprotect each frame, if we get a full frame. */ while (impl->protected_sb.length >= TSI_FAKE_FRAME_HEADER_SIZE) { @@ -462,7 +462,7 @@ static void fake_zero_copy_grpc_protector_destroy( tsi_zero_copy_grpc_protector* self) { if (self == nullptr) return; tsi_fake_zero_copy_grpc_protector* impl = - (tsi_fake_zero_copy_grpc_protector*)self; + reinterpret_cast<tsi_fake_zero_copy_grpc_protector*>(self); grpc_slice_buffer_destroy_internal(&impl->header_sb); grpc_slice_buffer_destroy_internal(&impl->protected_sb); gpr_free(impl); @@ -520,7 +520,7 @@ static tsi_result fake_handshaker_result_get_unused_bytes( } static void fake_handshaker_result_destroy(tsi_handshaker_result* self) { - fake_handshaker_result* result = (fake_handshaker_result*)self; + fake_handshaker_result* result = reinterpret_cast<fake_handshaker_result*>(self); gpr_free(result->unused_bytes); gpr_free(self); } @@ -541,10 +541,10 @@ static tsi_result fake_handshaker_result_create( return TSI_INVALID_ARGUMENT; } fake_handshaker_result* result = - (fake_handshaker_result*)gpr_zalloc(sizeof(*result)); + static_cast<fake_handshaker_result*>(gpr_zalloc(sizeof(*result))); result->base.vtable = &handshaker_result_vtable; if (unused_bytes_size > 0) { - result->unused_bytes = (unsigned char*)gpr_malloc(unused_bytes_size); + result->unused_bytes = static_cast<unsigned char*>(gpr_malloc(unused_bytes_size)); memcpy(result->unused_bytes, unused_bytes, unused_bytes_size); } result->unused_bytes_size = unused_bytes_size; @@ -556,7 +556,7 @@ static tsi_result fake_handshaker_result_create( static tsi_result fake_handshaker_get_bytes_to_send_to_peer( tsi_handshaker* self, unsigned char* bytes, size_t* bytes_size) { - tsi_fake_handshaker* impl = (tsi_fake_handshaker*)self; + tsi_fake_handshaker* impl = reinterpret_cast<tsi_fake_handshaker*>(self); tsi_result result = TSI_OK; if (impl->needs_incoming_message || impl->result == TSI_OK) { *bytes_size = 0; @@ -564,7 +564,7 @@ static tsi_result fake_handshaker_get_bytes_to_send_to_peer( } if (!impl->outgoing_frame.needs_draining) { tsi_fake_handshake_message next_message_to_send = - (tsi_fake_handshake_message)(impl->next_message_to_send + 2); + static_cast<tsi_fake_handshake_message>(impl->next_message_to_send + 2); const char* msg_string = tsi_fake_handshake_message_to_string(impl->next_message_to_send); result = tsi_fake_frame_set_data((unsigned char*)msg_string, @@ -598,9 +598,9 @@ static tsi_result fake_handshaker_get_bytes_to_send_to_peer( static tsi_result fake_handshaker_process_bytes_from_peer( tsi_handshaker* self, const unsigned char* bytes, size_t* bytes_size) { tsi_result result = TSI_OK; - tsi_fake_handshaker* impl = (tsi_fake_handshaker*)self; + tsi_fake_handshaker* impl = reinterpret_cast<tsi_fake_handshaker*>(self); tsi_fake_handshake_message expected_msg = - (tsi_fake_handshake_message)(impl->next_message_to_send - 1); + static_cast<tsi_fake_handshake_message>(impl->next_message_to_send - 1); tsi_fake_handshake_message received_msg; if (!impl->needs_incoming_message || impl->result == TSI_OK) { @@ -612,7 +612,7 @@ static tsi_result fake_handshaker_process_bytes_from_peer( /* We now have a complete frame. */ result = tsi_fake_handshake_message_from_string( - (const char*)impl->incoming_frame.data + TSI_FAKE_FRAME_HEADER_SIZE, + reinterpret_cast<const char*>(impl->incoming_frame.data) + TSI_FAKE_FRAME_HEADER_SIZE, &received_msg); if (result != TSI_OK) { impl->result = result; @@ -640,12 +640,12 @@ static tsi_result fake_handshaker_process_bytes_from_peer( } static tsi_result fake_handshaker_get_result(tsi_handshaker* self) { - tsi_fake_handshaker* impl = (tsi_fake_handshaker*)self; + tsi_fake_handshaker* impl = reinterpret_cast<tsi_fake_handshaker*>(self); return impl->result; } static void fake_handshaker_destroy(tsi_handshaker* self) { - tsi_fake_handshaker* impl = (tsi_fake_handshaker*)self; + tsi_fake_handshaker* impl = reinterpret_cast<tsi_fake_handshaker*>(self); tsi_fake_frame_destruct(&impl->incoming_frame); tsi_fake_frame_destruct(&impl->outgoing_frame); gpr_free(impl->outgoing_bytes_buffer); @@ -663,7 +663,7 @@ static tsi_result fake_handshaker_next( handshaker_result == nullptr) { return TSI_INVALID_ARGUMENT; } - tsi_fake_handshaker* handshaker = (tsi_fake_handshaker*)self; + tsi_fake_handshaker* handshaker = reinterpret_cast<tsi_fake_handshaker*>(self); tsi_result result = TSI_OK; /* Decode and process a handshake frame from the peer. */ @@ -685,8 +685,8 @@ static tsi_result fake_handshaker_next( if (result == TSI_INCOMPLETE_DATA) { handshaker->outgoing_bytes_buffer_size *= 2; handshaker->outgoing_bytes_buffer = - (unsigned char*)gpr_realloc(handshaker->outgoing_bytes_buffer, - handshaker->outgoing_bytes_buffer_size); + static_cast<unsigned char*>(gpr_realloc(handshaker->outgoing_bytes_buffer, + handshaker->outgoing_bytes_buffer_size)); } } while (result == TSI_INCOMPLETE_DATA); if (result != TSI_OK) return result; @@ -727,14 +727,14 @@ static const tsi_handshaker_vtable handshaker_vtable = { }; tsi_handshaker* tsi_create_fake_handshaker(int is_client) { - tsi_fake_handshaker* impl = (tsi_fake_handshaker*)gpr_zalloc(sizeof(*impl)); + tsi_fake_handshaker* impl = static_cast<tsi_fake_handshaker*>(gpr_zalloc(sizeof(*impl))); impl->base.vtable = &handshaker_vtable; impl->is_client = is_client; impl->result = TSI_HANDSHAKE_IN_PROGRESS; impl->outgoing_bytes_buffer_size = TSI_FAKE_HANDSHAKER_OUTGOING_BUFFER_INITIAL_SIZE; impl->outgoing_bytes_buffer = - (unsigned char*)gpr_malloc(impl->outgoing_bytes_buffer_size); + static_cast<unsigned char*>(gpr_malloc(impl->outgoing_bytes_buffer_size)); if (is_client) { impl->needs_incoming_message = 0; impl->next_message_to_send = TSI_FAKE_CLIENT_INIT; @@ -748,7 +748,7 @@ tsi_handshaker* tsi_create_fake_handshaker(int is_client) { tsi_frame_protector* tsi_create_fake_frame_protector( size_t* max_protected_frame_size) { tsi_fake_frame_protector* impl = - (tsi_fake_frame_protector*)gpr_zalloc(sizeof(*impl)); + static_cast<tsi_fake_frame_protector*>(gpr_zalloc(sizeof(*impl))); impl->max_frame_size = (max_protected_frame_size == nullptr) ? TSI_FAKE_DEFAULT_FRAME_SIZE : *max_protected_frame_size; @@ -759,7 +759,7 @@ tsi_frame_protector* tsi_create_fake_frame_protector( tsi_zero_copy_grpc_protector* tsi_create_fake_zero_copy_grpc_protector( size_t* max_protected_frame_size) { tsi_fake_zero_copy_grpc_protector* impl = - (tsi_fake_zero_copy_grpc_protector*)gpr_zalloc(sizeof(*impl)); + static_cast<tsi_fake_zero_copy_grpc_protector*>(gpr_zalloc(sizeof(*impl))); grpc_slice_buffer_init(&impl->header_sb); grpc_slice_buffer_init(&impl->protected_sb); impl->max_frame_size = (max_protected_frame_size == nullptr) diff --git a/src/core/tsi/ssl_transport_security.cc b/src/core/tsi/ssl_transport_security.cc index 6de02d4952..b32649a8b9 100644 --- a/src/core/tsi/ssl_transport_security.cc +++ b/src/core/tsi/ssl_transport_security.cc @@ -126,7 +126,7 @@ static void openssl_locking_cb(int mode, int type, const char* file, int line) { } static unsigned long openssl_thread_id_cb(void) { - return (unsigned long)gpr_thd_currentid(); + return static_cast<unsigned long>(gpr_thd_currentid()); } static void init_openssl(void) { @@ -137,7 +137,7 @@ static void init_openssl(void) { OpenSSL_add_all_algorithms(); num_locks = CRYPTO_num_locks(); GPR_ASSERT(num_locks > 0); - openssl_mutexes = (gpr_mu*)gpr_malloc((size_t)num_locks * sizeof(gpr_mu)); + openssl_mutexes = static_cast<gpr_mu*>(gpr_malloc(static_cast<size_t>(num_locks) * sizeof(gpr_mu))); for (i = 0; i < CRYPTO_num_locks(); i++) { gpr_mu_init(&openssl_mutexes[i]); } @@ -254,7 +254,7 @@ static tsi_result ssl_get_x509_common_name(X509* cert, unsigned char** utf8, gpr_log(GPR_ERROR, "Could not extract utf8 from asn1 string."); return TSI_OUT_OF_RESOURCES; } - *utf8_size = (size_t)utf8_returned_size; + *utf8_size = static_cast<size_t>(utf8_returned_size); return TSI_OK; } @@ -275,7 +275,7 @@ static tsi_result peer_property_from_x509_common_name( } result = tsi_construct_string_peer_property( TSI_X509_SUBJECT_COMMON_NAME_PEER_PROPERTY, - common_name == nullptr ? "" : (const char*)common_name, common_name_size, + common_name == nullptr ? "" : reinterpret_cast<const char*>(common_name), common_name_size, property); OPENSSL_free(common_name); return result; @@ -295,7 +295,7 @@ static tsi_result add_pem_certificate(X509* cert, tsi_peer_property* property) { return TSI_INTERNAL_ERROR; } tsi_result result = tsi_construct_string_peer_property( - TSI_X509_PEM_CERT_PROPERTY, (const char*)contents, (size_t)len, property); + TSI_X509_PEM_CERT_PROPERTY, (const char*)contents, static_cast<size_t>(len), property); BIO_free(bio); return result; } @@ -324,8 +324,8 @@ static tsi_result add_subject_alt_names_properties_to_peer( break; } result = tsi_construct_string_peer_property( - TSI_X509_SUBJECT_ALTERNATIVE_NAME_PEER_PROPERTY, (const char*)name, - (size_t)name_size, &peer->properties[peer->property_count++]); + TSI_X509_SUBJECT_ALTERNATIVE_NAME_PEER_PROPERTY, reinterpret_cast<const char*>(name), + static_cast<size_t>(name_size), &peer->properties[peer->property_count++]); OPENSSL_free(name); } else if (subject_alt_name->type == GEN_IPADD) { char ntop_buf[INET6_ADDRSTRLEN]; @@ -361,17 +361,17 @@ static tsi_result add_subject_alt_names_properties_to_peer( static tsi_result peer_from_x509(X509* cert, int include_certificate_type, tsi_peer* peer) { /* TODO(jboeuf): Maybe add more properties. */ - GENERAL_NAMES* subject_alt_names = (GENERAL_NAMES*)X509_get_ext_d2i( - cert, NID_subject_alt_name, nullptr, nullptr); + GENERAL_NAMES* subject_alt_names = static_cast<GENERAL_NAMES*>(X509_get_ext_d2i( + cert, NID_subject_alt_name, nullptr, nullptr)); int subject_alt_name_count = (subject_alt_names != nullptr) - ? (int)sk_GENERAL_NAME_num(subject_alt_names) + ? static_cast<int>(sk_GENERAL_NAME_num(subject_alt_names)) : 0; size_t property_count; tsi_result result; GPR_ASSERT(subject_alt_name_count >= 0); - property_count = (include_certificate_type ? (size_t)1 : 0) + + property_count = (include_certificate_type ? static_cast<size_t>(1) : 0) + 2 /* common name, certificate */ + - (size_t)subject_alt_name_count; + static_cast<size_t>(subject_alt_name_count); result = tsi_construct_peer(property_count, peer); if (result != TSI_OK) return result; do { @@ -391,7 +391,7 @@ static tsi_result peer_from_x509(X509* cert, int include_certificate_type, if (subject_alt_name_count != 0) { result = add_subject_alt_names_properties_to_peer( - peer, subject_alt_names, (size_t)subject_alt_name_count); + peer, subject_alt_names, static_cast<size_t>(subject_alt_name_count)); if (result != TSI_OK) break; } } while (0); @@ -408,7 +408,7 @@ static void log_ssl_error_stack(void) { unsigned long err; while ((err = ERR_get_error()) != 0) { char details[256]; - ERR_error_string_n((uint32_t)err, details, sizeof(details)); + ERR_error_string_n(static_cast<uint32_t>(err), details, sizeof(details)); gpr_log(GPR_ERROR, "%s", details); } } @@ -419,7 +419,7 @@ static tsi_result do_ssl_read(SSL* ssl, unsigned char* unprotected_bytes, int read_from_ssl; GPR_ASSERT(*unprotected_bytes_size <= INT_MAX); read_from_ssl = - SSL_read(ssl, unprotected_bytes, (int)*unprotected_bytes_size); + SSL_read(ssl, unprotected_bytes, static_cast<int>(*unprotected_bytes_size)); if (read_from_ssl <= 0) { read_from_ssl = SSL_get_error(ssl, read_from_ssl); switch (read_from_ssl) { @@ -442,7 +442,7 @@ static tsi_result do_ssl_read(SSL* ssl, unsigned char* unprotected_bytes, return TSI_PROTOCOL_FAILURE; } } - *unprotected_bytes_size = (size_t)read_from_ssl; + *unprotected_bytes_size = static_cast<size_t>(read_from_ssl); return TSI_OK; } @@ -452,7 +452,7 @@ static tsi_result do_ssl_write(SSL* ssl, unsigned char* unprotected_bytes, int ssl_write_result; GPR_ASSERT(unprotected_bytes_size <= INT_MAX); ssl_write_result = - SSL_write(ssl, unprotected_bytes, (int)unprotected_bytes_size); + SSL_write(ssl, unprotected_bytes, static_cast<int>(unprotected_bytes_size)); if (ssl_write_result < 0) { ssl_write_result = SSL_get_error(ssl, ssl_write_result); if (ssl_write_result == SSL_ERROR_WANT_READ) { @@ -476,7 +476,7 @@ static tsi_result ssl_ctx_use_certificate_chain(SSL_CTX* context, X509* certificate = nullptr; BIO* pem; GPR_ASSERT(pem_cert_chain_size <= INT_MAX); - pem = BIO_new_mem_buf((void*)pem_cert_chain, (int)pem_cert_chain_size); + pem = BIO_new_mem_buf((void*)pem_cert_chain, static_cast<int>(pem_cert_chain_size)); if (pem == nullptr) return TSI_OUT_OF_RESOURCES; do { @@ -519,7 +519,7 @@ static tsi_result ssl_ctx_use_private_key(SSL_CTX* context, const char* pem_key, EVP_PKEY* private_key = nullptr; BIO* pem; GPR_ASSERT(pem_key_size <= INT_MAX); - pem = BIO_new_mem_buf((void*)pem_key, (int)pem_key_size); + pem = BIO_new_mem_buf((void*)pem_key, static_cast<int>(pem_key_size)); if (pem == nullptr) return TSI_OUT_OF_RESOURCES; do { private_key = PEM_read_bio_PrivateKey(pem, nullptr, nullptr, (void*)""); @@ -551,7 +551,7 @@ static tsi_result ssl_ctx_load_verification_certs(SSL_CTX* context, BIO* pem; X509_STORE* root_store; GPR_ASSERT(pem_roots_size <= INT_MAX); - pem = BIO_new_mem_buf((void*)pem_roots, (int)pem_roots_size); + pem = BIO_new_mem_buf((void*)pem_roots, static_cast<int>(pem_roots_size)); root_store = SSL_CTX_get_cert_store(context); if (root_store == nullptr) return TSI_INVALID_ARGUMENT; if (pem == nullptr) return TSI_OUT_OF_RESOURCES; @@ -655,7 +655,7 @@ static tsi_result extract_x509_subject_names_from_pem_cert(const char* pem_cert, tsi_result result = TSI_OK; X509* cert = nullptr; BIO* pem; - pem = BIO_new_mem_buf((void*)pem_cert, (int)strlen(pem_cert)); + pem = BIO_new_mem_buf((void*)pem_cert, static_cast<int>(strlen(pem_cert))); if (pem == nullptr) return TSI_OUT_OF_RESOURCES; cert = PEM_read_bio_X509(pem, nullptr, nullptr, (void*)""); @@ -683,23 +683,23 @@ static tsi_result build_alpn_protocol_name_list( size_t length = alpn_protocols[i] == nullptr ? 0 : strlen(alpn_protocols[i]); if (length == 0 || length > 255) { - gpr_log(GPR_ERROR, "Invalid protocol name length: %d.", (int)length); + gpr_log(GPR_ERROR, "Invalid protocol name length: %d.", static_cast<int>(length)); return TSI_INVALID_ARGUMENT; } *protocol_name_list_length += length + 1; } - *protocol_name_list = (unsigned char*)gpr_malloc(*protocol_name_list_length); + *protocol_name_list = static_cast<unsigned char*>(gpr_malloc(*protocol_name_list_length)); if (*protocol_name_list == nullptr) return TSI_OUT_OF_RESOURCES; current = *protocol_name_list; for (i = 0; i < num_alpn_protocols; i++) { size_t length = strlen(alpn_protocols[i]); - *(current++) = (uint8_t)length; /* max checked above. */ + *(current++) = static_cast<uint8_t>(length); /* max checked above. */ memcpy(current, alpn_protocols[i], length); current += length; } /* Safety check. */ if ((current < *protocol_name_list) || - ((uintptr_t)(current - *protocol_name_list) != + (static_cast<uintptr_t>(current - *protocol_name_list) != *protocol_name_list_length)) { return TSI_INTERNAL_ERROR; } @@ -721,24 +721,24 @@ static tsi_result ssl_protector_protect(tsi_frame_protector* self, size_t* unprotected_bytes_size, unsigned char* protected_output_frames, size_t* protected_output_frames_size) { - tsi_ssl_frame_protector* impl = (tsi_ssl_frame_protector*)self; + tsi_ssl_frame_protector* impl = reinterpret_cast<tsi_ssl_frame_protector*>(self); int read_from_ssl; size_t available; tsi_result result = TSI_OK; /* First see if we have some pending data in the SSL BIO. */ - int pending_in_ssl = (int)BIO_pending(impl->network_io); + int pending_in_ssl = static_cast<int>(BIO_pending(impl->network_io)); if (pending_in_ssl > 0) { *unprotected_bytes_size = 0; GPR_ASSERT(*protected_output_frames_size <= INT_MAX); read_from_ssl = BIO_read(impl->network_io, protected_output_frames, - (int)*protected_output_frames_size); + static_cast<int>(*protected_output_frames_size)); if (read_from_ssl < 0) { gpr_log(GPR_ERROR, "Could not read from BIO even though some data is pending"); return TSI_INTERNAL_ERROR; } - *protected_output_frames_size = (size_t)read_from_ssl; + *protected_output_frames_size = static_cast<size_t>(read_from_ssl); return TSI_OK; } @@ -760,12 +760,12 @@ static tsi_result ssl_protector_protect(tsi_frame_protector* self, GPR_ASSERT(*protected_output_frames_size <= INT_MAX); read_from_ssl = BIO_read(impl->network_io, protected_output_frames, - (int)*protected_output_frames_size); + static_cast<int>(*protected_output_frames_size)); if (read_from_ssl < 0) { gpr_log(GPR_ERROR, "Could not read from BIO after SSL_write."); return TSI_INTERNAL_ERROR; } - *protected_output_frames_size = (size_t)read_from_ssl; + *protected_output_frames_size = static_cast<size_t>(read_from_ssl); *unprotected_bytes_size = available; impl->buffer_offset = 0; return TSI_OK; @@ -775,7 +775,7 @@ static tsi_result ssl_protector_protect_flush( tsi_frame_protector* self, unsigned char* protected_output_frames, size_t* protected_output_frames_size, size_t* still_pending_size) { tsi_result result = TSI_OK; - tsi_ssl_frame_protector* impl = (tsi_ssl_frame_protector*)self; + tsi_ssl_frame_protector* impl = reinterpret_cast<tsi_ssl_frame_protector*>(self); int read_from_ssl = 0; int pending; @@ -785,22 +785,22 @@ static tsi_result ssl_protector_protect_flush( impl->buffer_offset = 0; } - pending = (int)BIO_pending(impl->network_io); + pending = static_cast<int>(BIO_pending(impl->network_io)); GPR_ASSERT(pending >= 0); - *still_pending_size = (size_t)pending; + *still_pending_size = static_cast<size_t>(pending); if (*still_pending_size == 0) return TSI_OK; GPR_ASSERT(*protected_output_frames_size <= INT_MAX); read_from_ssl = BIO_read(impl->network_io, protected_output_frames, - (int)*protected_output_frames_size); + static_cast<int>(*protected_output_frames_size)); if (read_from_ssl <= 0) { gpr_log(GPR_ERROR, "Could not read from BIO after SSL_write."); return TSI_INTERNAL_ERROR; } - *protected_output_frames_size = (size_t)read_from_ssl; - pending = (int)BIO_pending(impl->network_io); + *protected_output_frames_size = static_cast<size_t>(read_from_ssl); + pending = static_cast<int>(BIO_pending(impl->network_io)); GPR_ASSERT(pending >= 0); - *still_pending_size = (size_t)pending; + *still_pending_size = static_cast<size_t>(pending); return TSI_OK; } @@ -812,7 +812,7 @@ static tsi_result ssl_protector_unprotect( int written_into_ssl = 0; size_t output_bytes_size = *unprotected_bytes_size; size_t output_bytes_offset = 0; - tsi_ssl_frame_protector* impl = (tsi_ssl_frame_protector*)self; + tsi_ssl_frame_protector* impl = reinterpret_cast<tsi_ssl_frame_protector*>(self); /* First, try to read remaining data from ssl. */ result = do_ssl_read(impl->ssl, unprotected_bytes, unprotected_bytes_size); @@ -829,13 +829,13 @@ static tsi_result ssl_protector_unprotect( /* Then, try to write some data to ssl. */ GPR_ASSERT(*protected_frames_bytes_size <= INT_MAX); written_into_ssl = BIO_write(impl->network_io, protected_frames_bytes, - (int)*protected_frames_bytes_size); + static_cast<int>(*protected_frames_bytes_size)); if (written_into_ssl < 0) { gpr_log(GPR_ERROR, "Sending protected frame to ssl failed with %d", written_into_ssl); return TSI_INTERNAL_ERROR; } - *protected_frames_bytes_size = (size_t)written_into_ssl; + *protected_frames_bytes_size = static_cast<size_t>(written_into_ssl); /* Now try to read some data again. */ result = do_ssl_read(impl->ssl, unprotected_bytes, unprotected_bytes_size); @@ -847,7 +847,7 @@ static tsi_result ssl_protector_unprotect( } static void ssl_protector_destroy(tsi_frame_protector* self) { - tsi_ssl_frame_protector* impl = (tsi_ssl_frame_protector*)self; + tsi_ssl_frame_protector* impl = reinterpret_cast<tsi_ssl_frame_protector*>(self); if (impl->buffer != nullptr) gpr_free(impl->buffer); if (impl->ssl != nullptr) SSL_free(impl->ssl); if (impl->network_io != nullptr) BIO_free(impl->network_io); @@ -907,14 +907,14 @@ static void tsi_ssl_handshaker_factory_init( static tsi_result ssl_handshaker_get_bytes_to_send_to_peer(tsi_handshaker* self, unsigned char* bytes, size_t* bytes_size) { - tsi_ssl_handshaker* impl = (tsi_ssl_handshaker*)self; + tsi_ssl_handshaker* impl = reinterpret_cast<tsi_ssl_handshaker*>(self); int bytes_read_from_ssl = 0; if (bytes == nullptr || bytes_size == nullptr || *bytes_size == 0 || *bytes_size > INT_MAX) { return TSI_INVALID_ARGUMENT; } GPR_ASSERT(*bytes_size <= INT_MAX); - bytes_read_from_ssl = BIO_read(impl->network_io, bytes, (int)*bytes_size); + bytes_read_from_ssl = BIO_read(impl->network_io, bytes, static_cast<int>(*bytes_size)); if (bytes_read_from_ssl < 0) { *bytes_size = 0; if (!BIO_should_retry(impl->network_io)) { @@ -924,12 +924,12 @@ static tsi_result ssl_handshaker_get_bytes_to_send_to_peer(tsi_handshaker* self, return TSI_OK; } } - *bytes_size = (size_t)bytes_read_from_ssl; + *bytes_size = static_cast<size_t>(bytes_read_from_ssl); return BIO_pending(impl->network_io) == 0 ? TSI_OK : TSI_INCOMPLETE_DATA; } static tsi_result ssl_handshaker_get_result(tsi_handshaker* self) { - tsi_ssl_handshaker* impl = (tsi_ssl_handshaker*)self; + tsi_ssl_handshaker* impl = reinterpret_cast<tsi_ssl_handshaker*>(self); if ((impl->result == TSI_HANDSHAKE_IN_PROGRESS) && SSL_is_init_finished(impl->ssl)) { impl->result = TSI_OK; @@ -939,20 +939,20 @@ static tsi_result ssl_handshaker_get_result(tsi_handshaker* self) { static tsi_result ssl_handshaker_process_bytes_from_peer( tsi_handshaker* self, const unsigned char* bytes, size_t* bytes_size) { - tsi_ssl_handshaker* impl = (tsi_ssl_handshaker*)self; + tsi_ssl_handshaker* impl = reinterpret_cast<tsi_ssl_handshaker*>(self); int bytes_written_into_ssl_size = 0; if (bytes == nullptr || bytes_size == nullptr || *bytes_size > INT_MAX) { return TSI_INVALID_ARGUMENT; } GPR_ASSERT(*bytes_size <= INT_MAX); bytes_written_into_ssl_size = - BIO_write(impl->network_io, bytes, (int)*bytes_size); + BIO_write(impl->network_io, bytes, static_cast<int>(*bytes_size)); if (bytes_written_into_ssl_size < 0) { gpr_log(GPR_ERROR, "Could not write to memory BIO."); impl->result = TSI_INTERNAL_ERROR; return impl->result; } - *bytes_size = (size_t)bytes_written_into_ssl_size; + *bytes_size = static_cast<size_t>(bytes_written_into_ssl_size); if (!tsi_handshaker_is_in_progress(self)) { impl->result = TSI_OK; @@ -988,7 +988,7 @@ static tsi_result ssl_handshaker_extract_peer(tsi_handshaker* self, tsi_result result = TSI_OK; const unsigned char* alpn_selected = nullptr; unsigned int alpn_selected_len; - tsi_ssl_handshaker* impl = (tsi_ssl_handshaker*)self; + tsi_ssl_handshaker* impl = reinterpret_cast<tsi_ssl_handshaker*>(self); X509* peer_cert = SSL_get_peer_certificate(impl->ssl); if (peer_cert != nullptr) { result = peer_from_x509(peer_cert, 1, peer); @@ -1005,13 +1005,13 @@ static tsi_result ssl_handshaker_extract_peer(tsi_handshaker* self, } if (alpn_selected != nullptr) { size_t i; - tsi_peer_property* new_properties = (tsi_peer_property*)gpr_zalloc( - sizeof(*new_properties) * (peer->property_count + 1)); + tsi_peer_property* new_properties = static_cast<tsi_peer_property*>(gpr_zalloc( + sizeof(*new_properties) * (peer->property_count + 1))); for (i = 0; i < peer->property_count; i++) { new_properties[i] = peer->properties[i]; } result = tsi_construct_string_peer_property( - TSI_SSL_ALPN_SELECTED_PROTOCOL, (const char*)alpn_selected, + TSI_SSL_ALPN_SELECTED_PROTOCOL, reinterpret_cast<const char*>(alpn_selected), alpn_selected_len, &new_properties[peer->property_count]); if (result != TSI_OK) { gpr_free(new_properties); @@ -1029,9 +1029,9 @@ static tsi_result ssl_handshaker_create_frame_protector( tsi_frame_protector** protector) { size_t actual_max_output_protected_frame_size = TSI_SSL_MAX_PROTECTED_FRAME_SIZE_UPPER_BOUND; - tsi_ssl_handshaker* impl = (tsi_ssl_handshaker*)self; + tsi_ssl_handshaker* impl = reinterpret_cast<tsi_ssl_handshaker*>(self); tsi_ssl_frame_protector* protector_impl = - (tsi_ssl_frame_protector*)gpr_zalloc(sizeof(*protector_impl)); + static_cast<tsi_ssl_frame_protector*>(gpr_zalloc(sizeof(*protector_impl))); if (max_output_protected_frame_size != nullptr) { if (*max_output_protected_frame_size > @@ -1048,7 +1048,7 @@ static tsi_result ssl_handshaker_create_frame_protector( protector_impl->buffer_size = actual_max_output_protected_frame_size - TSI_SSL_MAX_PROTECTION_OVERHEAD; protector_impl->buffer = - (unsigned char*)gpr_malloc(protector_impl->buffer_size); + static_cast<unsigned char*>(gpr_malloc(protector_impl->buffer_size)); if (protector_impl->buffer == nullptr) { gpr_log(GPR_ERROR, "Could not allocated buffer for tsi_ssl_frame_protector."); @@ -1070,7 +1070,7 @@ static tsi_result ssl_handshaker_create_frame_protector( } static void ssl_handshaker_destroy(tsi_handshaker* self) { - tsi_ssl_handshaker* impl = (tsi_ssl_handshaker*)self; + tsi_ssl_handshaker* impl = reinterpret_cast<tsi_ssl_handshaker*>(self); SSL_free(impl->ssl); BIO_free(impl->network_io); tsi_ssl_handshaker_factory_unref(impl->factory_ref); @@ -1139,7 +1139,7 @@ static tsi_result create_tsi_ssl_handshaker(SSL_CTX* ctx, int is_client, SSL_set_accept_state(ssl); } - impl = (tsi_ssl_handshaker*)gpr_zalloc(sizeof(*impl)); + impl = static_cast<tsi_ssl_handshaker*>(gpr_zalloc(sizeof(*impl))); impl->ssl = ssl; impl->network_io = network_io; impl->result = TSI_HANDSHAKE_IN_PROGRESS; @@ -1157,11 +1157,11 @@ static int select_protocol_list(const unsigned char** out, const unsigned char* server_list, size_t server_list_len) { const unsigned char* client_current = client_list; - while ((unsigned int)(client_current - client_list) < client_list_len) { + while (static_cast<unsigned int>(client_current - client_list) < client_list_len) { unsigned char client_current_len = *(client_current++); const unsigned char* server_current = server_list; while ((server_current >= server_list) && - (uintptr_t)(server_current - server_list) < server_list_len) { + static_cast<uintptr_t>(server_current - server_list) < server_list_len) { unsigned char server_current_len = *(server_current++); if ((client_current_len == server_current_len) && !memcmp(client_current, server_current, server_current_len)) { @@ -1195,7 +1195,7 @@ static void tsi_ssl_client_handshaker_factory_destroy( tsi_ssl_handshaker_factory* factory) { if (factory == nullptr) return; tsi_ssl_client_handshaker_factory* self = - (tsi_ssl_client_handshaker_factory*)factory; + reinterpret_cast<tsi_ssl_client_handshaker_factory*>(factory); if (self->ssl_context != nullptr) SSL_CTX_free(self->ssl_context); if (self->alpn_protocol_list != nullptr) gpr_free(self->alpn_protocol_list); gpr_free(self); @@ -1207,7 +1207,7 @@ static int client_handshaker_factory_npn_callback(SSL* ssl, unsigned char** out, unsigned int inlen, void* arg) { tsi_ssl_client_handshaker_factory* factory = - (tsi_ssl_client_handshaker_factory*)arg; + static_cast<tsi_ssl_client_handshaker_factory*>(arg); return select_protocol_list((const unsigned char**)out, outlen, factory->alpn_protocol_list, factory->alpn_protocol_list_length, in, inlen); @@ -1234,7 +1234,7 @@ static void tsi_ssl_server_handshaker_factory_destroy( tsi_ssl_handshaker_factory* factory) { if (factory == nullptr) return; tsi_ssl_server_handshaker_factory* self = - (tsi_ssl_server_handshaker_factory*)factory; + reinterpret_cast<tsi_ssl_server_handshaker_factory*>(factory); size_t i; for (i = 0; i < self->ssl_context_count; i++) { if (self->ssl_contexts[i] != nullptr) { @@ -1301,7 +1301,7 @@ static int does_entry_match_name(const char* entry, size_t entry_length, static int ssl_server_handshaker_factory_servername_callback(SSL* ssl, int* ap, void* arg) { tsi_ssl_server_handshaker_factory* impl = - (tsi_ssl_server_handshaker_factory*)arg; + static_cast<tsi_ssl_server_handshaker_factory*>(arg); size_t i = 0; const char* servername = SSL_get_servername(ssl, TLSEXT_NAMETYPE_host_name); if (servername == nullptr || strlen(servername) == 0) { @@ -1324,7 +1324,7 @@ static int server_handshaker_factory_alpn_callback( SSL* ssl, const unsigned char** out, unsigned char* outlen, const unsigned char* in, unsigned int inlen, void* arg) { tsi_ssl_server_handshaker_factory* factory = - (tsi_ssl_server_handshaker_factory*)arg; + static_cast<tsi_ssl_server_handshaker_factory*>(arg); return select_protocol_list(out, outlen, in, inlen, factory->alpn_protocol_list, factory->alpn_protocol_list_length); @@ -1334,10 +1334,10 @@ static int server_handshaker_factory_alpn_callback( static int server_handshaker_factory_npn_advertised_callback( SSL* ssl, const unsigned char** out, unsigned int* outlen, void* arg) { tsi_ssl_server_handshaker_factory* factory = - (tsi_ssl_server_handshaker_factory*)arg; + static_cast<tsi_ssl_server_handshaker_factory*>(arg); *out = factory->alpn_protocol_list; GPR_ASSERT(factory->alpn_protocol_list_length <= UINT_MAX); - *outlen = (unsigned int)factory->alpn_protocol_list_length; + *outlen = static_cast<unsigned int>(factory->alpn_protocol_list_length); return SSL_TLSEXT_ERR_OK; } @@ -1367,7 +1367,7 @@ tsi_result tsi_create_ssl_client_handshaker_factory( return TSI_INVALID_ARGUMENT; } - impl = (tsi_ssl_client_handshaker_factory*)gpr_zalloc(sizeof(*impl)); + impl = static_cast<tsi_ssl_client_handshaker_factory*>(gpr_zalloc(sizeof(*impl))); tsi_ssl_handshaker_factory_init(&impl->base); impl->base.vtable = &client_handshaker_factory_vtable; @@ -1397,7 +1397,7 @@ tsi_result tsi_create_ssl_client_handshaker_factory( GPR_ASSERT(impl->alpn_protocol_list_length < UINT_MAX); if (SSL_CTX_set_alpn_protos( ssl_context, impl->alpn_protocol_list, - (unsigned int)impl->alpn_protocol_list_length)) { + static_cast<unsigned int>(impl->alpn_protocol_list_length))) { gpr_log(GPR_ERROR, "Could not set alpn protocol list to context."); result = TSI_INVALID_ARGUMENT; break; @@ -1452,14 +1452,14 @@ tsi_result tsi_create_ssl_server_handshaker_factory_ex( return TSI_INVALID_ARGUMENT; } - impl = (tsi_ssl_server_handshaker_factory*)gpr_zalloc(sizeof(*impl)); + impl = static_cast<tsi_ssl_server_handshaker_factory*>(gpr_zalloc(sizeof(*impl))); tsi_ssl_handshaker_factory_init(&impl->base); impl->base.vtable = &server_handshaker_factory_vtable; impl->ssl_contexts = - (SSL_CTX**)gpr_zalloc(num_key_cert_pairs * sizeof(SSL_CTX*)); + static_cast<SSL_CTX**>(gpr_zalloc(num_key_cert_pairs * sizeof(SSL_CTX*))); impl->ssl_context_x509_subject_names = - (tsi_peer*)gpr_zalloc(num_key_cert_pairs * sizeof(tsi_peer)); + static_cast<tsi_peer*>(gpr_zalloc(num_key_cert_pairs * sizeof(tsi_peer))); if (impl->ssl_contexts == nullptr || impl->ssl_context_x509_subject_names == nullptr) { tsi_ssl_handshaker_factory_unref(&impl->base); diff --git a/src/core/tsi/transport_security.cc b/src/core/tsi/transport_security.cc index 5abd2f0f68..5cfdf6fc32 100644 --- a/src/core/tsi/transport_security.cc +++ b/src/core/tsi/transport_security.cc @@ -288,7 +288,7 @@ tsi_result tsi_construct_allocated_string_peer_property( *property = tsi_init_peer_property(); if (name != nullptr) property->name = gpr_strdup(name); if (value_length > 0) { - property->value.data = (char*)gpr_zalloc(value_length); + property->value.data = static_cast<char*>(gpr_zalloc(value_length)); property->value.length = value_length; } return TSI_OK; @@ -316,8 +316,8 @@ tsi_result tsi_construct_string_peer_property(const char* name, tsi_result tsi_construct_peer(size_t property_count, tsi_peer* peer) { memset(peer, 0, sizeof(tsi_peer)); if (property_count > 0) { - peer->properties = (tsi_peer_property*)gpr_zalloc( - property_count * sizeof(tsi_peer_property)); + peer->properties = static_cast<tsi_peer_property*>(gpr_zalloc( + property_count * sizeof(tsi_peer_property))); peer->property_count = property_count; } return TSI_OK; diff --git a/src/core/tsi/transport_security_adapter.cc b/src/core/tsi/transport_security_adapter.cc index 56dec55494..e57a42ad6c 100644 --- a/src/core/tsi/transport_security_adapter.cc +++ b/src/core/tsi/transport_security_adapter.cc @@ -59,7 +59,7 @@ static tsi_result adapter_result_get_unused_bytes( } static void adapter_result_destroy(tsi_handshaker_result* self) { - tsi_adapter_handshaker_result* impl = (tsi_adapter_handshaker_result*)self; + tsi_adapter_handshaker_result* impl = reinterpret_cast<tsi_adapter_handshaker_result*>(self); tsi_handshaker_destroy(impl->wrapped); gpr_free(impl->unused_bytes); gpr_free(self); @@ -82,12 +82,12 @@ static tsi_result tsi_adapter_create_handshaker_result( return TSI_INVALID_ARGUMENT; } tsi_adapter_handshaker_result* impl = - (tsi_adapter_handshaker_result*)gpr_zalloc(sizeof(*impl)); + static_cast<tsi_adapter_handshaker_result*>(gpr_zalloc(sizeof(*impl))); impl->base.vtable = &result_vtable; impl->wrapped = wrapped; impl->unused_bytes_size = unused_bytes_size; if (unused_bytes_size > 0) { - impl->unused_bytes = (unsigned char*)gpr_malloc(unused_bytes_size); + impl->unused_bytes = static_cast<unsigned char*>(gpr_malloc(unused_bytes_size)); memcpy(impl->unused_bytes, unused_bytes, unused_bytes_size); } else { impl->unused_bytes = nullptr; @@ -137,7 +137,7 @@ static tsi_result adapter_create_frame_protector( } static void adapter_destroy(tsi_handshaker* self) { - tsi_adapter_handshaker* impl = (tsi_adapter_handshaker*)self; + tsi_adapter_handshaker* impl = reinterpret_cast<tsi_adapter_handshaker*>(self); tsi_handshaker_destroy(impl->wrapped); gpr_free(impl->adapter_buffer); gpr_free(self); @@ -156,7 +156,7 @@ static tsi_result adapter_next( } /* If there are received bytes, process them first. */ - tsi_adapter_handshaker* impl = (tsi_adapter_handshaker*)self; + tsi_adapter_handshaker* impl = reinterpret_cast<tsi_adapter_handshaker*>(self); tsi_result status = TSI_OK; size_t bytes_consumed = received_bytes_size; if (received_bytes_size > 0) { @@ -174,8 +174,8 @@ static tsi_result adapter_next( offset += to_send_size; if (status == TSI_INCOMPLETE_DATA) { impl->adapter_buffer_size *= 2; - impl->adapter_buffer = (unsigned char*)gpr_realloc( - impl->adapter_buffer, impl->adapter_buffer_size); + impl->adapter_buffer = static_cast<unsigned char*>(gpr_realloc( + impl->adapter_buffer, impl->adapter_buffer_size)); } } while (status == TSI_INCOMPLETE_DATA); if (status != TSI_OK) return status; @@ -212,16 +212,16 @@ static const tsi_handshaker_vtable handshaker_vtable = { tsi_handshaker* tsi_create_adapter_handshaker(tsi_handshaker* wrapped) { GPR_ASSERT(wrapped != nullptr); tsi_adapter_handshaker* impl = - (tsi_adapter_handshaker*)gpr_zalloc(sizeof(*impl)); + static_cast<tsi_adapter_handshaker*>(gpr_zalloc(sizeof(*impl))); impl->base.vtable = &handshaker_vtable; impl->wrapped = wrapped; impl->adapter_buffer_size = TSI_ADAPTER_INITIAL_BUFFER_SIZE; - impl->adapter_buffer = (unsigned char*)gpr_malloc(impl->adapter_buffer_size); + impl->adapter_buffer = static_cast<unsigned char*>(gpr_malloc(impl->adapter_buffer_size)); return &impl->base; } tsi_handshaker* tsi_adapter_handshaker_get_wrapped(tsi_handshaker* adapter) { if (adapter == nullptr) return nullptr; - tsi_adapter_handshaker* impl = (tsi_adapter_handshaker*)adapter; + tsi_adapter_handshaker* impl = reinterpret_cast<tsi_adapter_handshaker*>(adapter); return impl->wrapped; } |