From be82e64b3debcdb1d9ec6a149fc85af0d46bfb7e Mon Sep 17 00:00:00 2001 From: Noah Eisen Date: Fri, 9 Feb 2018 09:16:55 -0800 Subject: Autofix c casts to c++ casts --- test/core/util/cmdline.cc | 20 ++++++++++---------- test/core/util/debugger_macros.cc | 2 +- test/core/util/histogram.cc | 14 +++++++------- test/core/util/memory_counters.cc | 8 ++++---- test/core/util/mock_endpoint.cc | 14 +++++++------- test/core/util/parse_hexstring.cc | 4 ++-- test/core/util/passthru_endpoint.cc | 20 ++++++++++---------- test/core/util/port.cc | 2 +- test/core/util/port_server_client.cc | 12 ++++++------ test/core/util/reconnect_server.cc | 4 ++-- test/core/util/slice_splitter.cc | 8 ++++---- test/core/util/subprocess_posix.cc | 6 +++--- test/core/util/test_config.cc | 8 ++++---- test/core/util/test_tcp_server.cc | 4 ++-- test/core/util/trickle_endpoint.cc | 32 ++++++++++++++++---------------- 15 files changed, 79 insertions(+), 79 deletions(-) (limited to 'test/core/util') diff --git a/test/core/util/cmdline.cc b/test/core/util/cmdline.cc index 20bce273cd..fd3959bfe9 100644 --- a/test/core/util/cmdline.cc +++ b/test/core/util/cmdline.cc @@ -56,7 +56,7 @@ struct gpr_cmdline { static int normal_state(gpr_cmdline* cl, char* arg); gpr_cmdline* gpr_cmdline_create(const char* description) { - gpr_cmdline* cl = (gpr_cmdline*)gpr_zalloc(sizeof(gpr_cmdline)); + gpr_cmdline* cl = static_cast(gpr_zalloc(sizeof(gpr_cmdline))); cl->description = description; cl->state = normal_state; @@ -85,7 +85,7 @@ static void add_arg(gpr_cmdline* cl, const char* name, const char* help, GPR_ASSERT(0 != strcmp(a->name, name)); } - a = (arg*)gpr_zalloc(sizeof(arg)); + a = static_cast(gpr_zalloc(sizeof(arg))); a->name = name; a->help = help; a->type = type; @@ -223,13 +223,13 @@ static int value_state(gpr_cmdline* cl, char* str) { cl->cur_arg->name); return print_usage_and_die(cl); } - *(int*)cl->cur_arg->value = (int)intval; + *static_cast(cl->cur_arg->value) = static_cast(intval); break; case ARGTYPE_BOOL: if (0 == strcmp(str, "1") || 0 == strcmp(str, "true")) { - *(int*)cl->cur_arg->value = 1; + *static_cast(cl->cur_arg->value) = 1; } else if (0 == strcmp(str, "0") || 0 == strcmp(str, "false")) { - *(int*)cl->cur_arg->value = 0; + *static_cast(cl->cur_arg->value) = 0; } else { fprintf(stderr, "expected boolean, got '%s' for %s\n", str, cl->cur_arg->name); @@ -237,7 +237,7 @@ static int value_state(gpr_cmdline* cl, char* str) { } break; case ARGTYPE_STRING: - *(char**)cl->cur_arg->value = str; + *static_cast(cl->cur_arg->value) = str; break; } @@ -281,14 +281,14 @@ static int normal_state(gpr_cmdline* cl, char* str) { fprintf(stderr, "%s is not a flag argument\n", str); return print_usage_and_die(cl); } - *(int*)cl->cur_arg->value = 0; + *static_cast(cl->cur_arg->value) = 0; return 1; /* early out */ } eq = strchr(str, '='); if (eq != nullptr) { /* copy the string into a temp buffer and extract the name */ - tmp = arg_name = (char*)gpr_malloc((size_t)(eq - str + 1)); - memcpy(arg_name, str, (size_t)(eq - str)); + tmp = arg_name = static_cast(gpr_malloc(static_cast(eq - str + 1))); + memcpy(arg_name, str, static_cast(eq - str)); arg_name[eq - str] = 0; } else { arg_name = str; @@ -305,7 +305,7 @@ static int normal_state(gpr_cmdline* cl, char* str) { cl->state = value_state; } else { /* flag parameter: just set the value */ - *(int*)cl->cur_arg->value = 1; + *static_cast(cl->cur_arg->value) = 1; } } else { r = extra_state(cl, str); diff --git a/test/core/util/debugger_macros.cc b/test/core/util/debugger_macros.cc index bb96fc7054..0ec5f1db6b 100644 --- a/test/core/util/debugger_macros.cc +++ b/test/core/util/debugger_macros.cc @@ -54,5 +54,5 @@ grpc_stream* grpc_transport_stream_from_call(grpc_call* call) { } grpc_chttp2_stream* grpc_chttp2_stream_from_call(grpc_call* call) { - return (grpc_chttp2_stream*)grpc_transport_stream_from_call(call); + return reinterpret_cast(grpc_transport_stream_from_call(call)); } diff --git a/test/core/util/histogram.cc b/test/core/util/histogram.cc index b2518279ac..6eb0342ede 100644 --- a/test/core/util/histogram.cc +++ b/test/core/util/histogram.cc @@ -57,7 +57,7 @@ struct grpc_histogram { /* determine a bucket index given a value - does no bounds checking */ static size_t bucket_for_unchecked(grpc_histogram* h, double x) { - return (size_t)(log(x) * h->one_on_log_multiplier); + return static_cast(log(x) * h->one_on_log_multiplier); } /* bounds checked version of the above */ @@ -74,7 +74,7 @@ static double bucket_start(grpc_histogram* h, double x) { grpc_histogram* grpc_histogram_create(double resolution, double max_bucket_start) { - grpc_histogram* h = (grpc_histogram*)gpr_malloc(sizeof(grpc_histogram)); + grpc_histogram* h = static_cast(gpr_malloc(sizeof(grpc_histogram))); GPR_ASSERT(resolution > 0.0); GPR_ASSERT(max_bucket_start > resolution); h->sum = 0.0; @@ -88,7 +88,7 @@ grpc_histogram* grpc_histogram_create(double resolution, h->num_buckets = bucket_for_unchecked(h, max_bucket_start) + 1; GPR_ASSERT(h->num_buckets > 1); GPR_ASSERT(h->num_buckets < 100000000); - h->buckets = (uint32_t*)gpr_zalloc(sizeof(uint32_t) * h->num_buckets); + h->buckets = static_cast(gpr_zalloc(sizeof(uint32_t) * h->num_buckets)); return h; } @@ -176,14 +176,14 @@ static double threshold_for_count_below(grpc_histogram* h, double count_below) { break; } } - return (bucket_start(h, (double)lower_idx) + - bucket_start(h, (double)upper_idx)) / + return (bucket_start(h, static_cast(lower_idx)) + + bucket_start(h, static_cast(upper_idx))) / 2.0; } else { /* treat values as uniform throughout the bucket, and find where this value should lie */ - lower_bound = bucket_start(h, (double)lower_idx); - upper_bound = bucket_start(h, (double)(lower_idx + 1)); + lower_bound = bucket_start(h, static_cast(lower_idx)); + upper_bound = bucket_start(h, static_cast(lower_idx + 1)); return GPR_CLAMP(upper_bound - (upper_bound - lower_bound) * (count_so_far - count_below) / h->buckets[lower_idx], diff --git a/test/core/util/memory_counters.cc b/test/core/util/memory_counters.cc index 32d7b89c9a..4960fe0757 100644 --- a/test/core/util/memory_counters.cc +++ b/test/core/util/memory_counters.cc @@ -48,13 +48,13 @@ static void* guard_malloc(size_t size) { NO_BARRIER_FETCH_ADD(&g_memory_counters.total_size_relative, (gpr_atm)size); NO_BARRIER_FETCH_ADD(&g_memory_counters.total_allocs_absolute, (gpr_atm)1); NO_BARRIER_FETCH_ADD(&g_memory_counters.total_allocs_relative, (gpr_atm)1); - ptr = (size_t*)g_old_allocs.malloc_fn(size + sizeof(size)); + ptr = static_cast(g_old_allocs.malloc_fn(size + sizeof(size))); *ptr++ = size; return ptr; } static void* guard_realloc(void* vptr, size_t size) { - size_t* ptr = (size_t*)vptr; + size_t* ptr = static_cast(vptr); if (vptr == nullptr) { return guard_malloc(size); } @@ -67,13 +67,13 @@ static void* guard_realloc(void* vptr, size_t size) { NO_BARRIER_FETCH_ADD(&g_memory_counters.total_size_relative, -(gpr_atm)*ptr); NO_BARRIER_FETCH_ADD(&g_memory_counters.total_size_relative, (gpr_atm)size); NO_BARRIER_FETCH_ADD(&g_memory_counters.total_allocs_absolute, (gpr_atm)1); - ptr = (size_t*)g_old_allocs.realloc_fn(ptr, size + sizeof(size)); + ptr = static_cast(g_old_allocs.realloc_fn(ptr, size + sizeof(size))); *ptr++ = size; return ptr; } static void guard_free(void* vptr) { - size_t* ptr = (size_t*)vptr; + size_t* ptr = static_cast(vptr); if (!vptr) return; --ptr; NO_BARRIER_FETCH_ADD(&g_memory_counters.total_size_relative, -(gpr_atm)*ptr); diff --git a/test/core/util/mock_endpoint.cc b/test/core/util/mock_endpoint.cc index 4b35a581b1..37a1b622e4 100644 --- a/test/core/util/mock_endpoint.cc +++ b/test/core/util/mock_endpoint.cc @@ -42,7 +42,7 @@ typedef struct grpc_mock_endpoint { static void me_read(grpc_endpoint* ep, grpc_slice_buffer* slices, grpc_closure* cb) { - grpc_mock_endpoint* m = (grpc_mock_endpoint*)ep; + grpc_mock_endpoint* m = reinterpret_cast(ep); gpr_mu_lock(&m->mu); if (m->read_buffer.count > 0) { grpc_slice_buffer_swap(&m->read_buffer, slices); @@ -56,7 +56,7 @@ static void me_read(grpc_endpoint* ep, grpc_slice_buffer* slices, static void me_write(grpc_endpoint* ep, grpc_slice_buffer* slices, grpc_closure* cb) { - grpc_mock_endpoint* m = (grpc_mock_endpoint*)ep; + grpc_mock_endpoint* m = reinterpret_cast(ep); for (size_t i = 0; i < slices->count; i++) { m->on_write(slices->slices[i]); } @@ -72,7 +72,7 @@ static void me_delete_from_pollset_set(grpc_endpoint* ep, grpc_pollset_set* pollset) {} static void me_shutdown(grpc_endpoint* ep, grpc_error* why) { - grpc_mock_endpoint* m = (grpc_mock_endpoint*)ep; + grpc_mock_endpoint* m = reinterpret_cast(ep); gpr_mu_lock(&m->mu); if (m->on_read) { GRPC_CLOSURE_SCHED(m->on_read, @@ -86,7 +86,7 @@ static void me_shutdown(grpc_endpoint* ep, grpc_error* why) { } static void me_destroy(grpc_endpoint* ep) { - grpc_mock_endpoint* m = (grpc_mock_endpoint*)ep; + grpc_mock_endpoint* m = reinterpret_cast(ep); grpc_slice_buffer_destroy(&m->read_buffer); grpc_resource_user_unref(m->resource_user); gpr_free(m); @@ -97,7 +97,7 @@ static char* me_get_peer(grpc_endpoint* ep) { } static grpc_resource_user* me_get_resource_user(grpc_endpoint* ep) { - grpc_mock_endpoint* m = (grpc_mock_endpoint*)ep; + grpc_mock_endpoint* m = reinterpret_cast(ep); return m->resource_user; } @@ -118,7 +118,7 @@ static const grpc_endpoint_vtable vtable = { grpc_endpoint* grpc_mock_endpoint_create(void (*on_write)(grpc_slice slice), grpc_resource_quota* resource_quota) { - grpc_mock_endpoint* m = (grpc_mock_endpoint*)gpr_malloc(sizeof(*m)); + grpc_mock_endpoint* m = static_cast(gpr_malloc(sizeof(*m))); m->base.vtable = &vtable; char* name; gpr_asprintf(&name, "mock_endpoint_%" PRIxPTR, (intptr_t)m); @@ -132,7 +132,7 @@ grpc_endpoint* grpc_mock_endpoint_create(void (*on_write)(grpc_slice slice), } void grpc_mock_endpoint_put_read(grpc_endpoint* ep, grpc_slice slice) { - grpc_mock_endpoint* m = (grpc_mock_endpoint*)ep; + grpc_mock_endpoint* m = reinterpret_cast(ep); gpr_mu_lock(&m->mu); if (m->on_read != nullptr) { grpc_slice_buffer_add(m->on_read_out, slice); diff --git a/test/core/util/parse_hexstring.cc b/test/core/util/parse_hexstring.cc index 622642a298..7ba6776bc2 100644 --- a/test/core/util/parse_hexstring.cc +++ b/test/core/util/parse_hexstring.cc @@ -39,10 +39,10 @@ grpc_slice parse_hexstring(const char* hexstring) { temp = 0; for (p = hexstring; *p; p++) { if (*p >= '0' && *p <= '9') { - temp = (uint8_t)(temp << 4) | (uint8_t)(*p - '0'); + temp = static_cast(temp << 4) | static_cast(*p - '0'); nibbles++; } else if (*p >= 'a' && *p <= 'f') { - temp = (uint8_t)(temp << 4) | (uint8_t)(*p - 'a' + 10); + temp = static_cast(temp << 4) | static_cast(*p - 'a' + 10); nibbles++; } if (nibbles == 2) { diff --git a/test/core/util/passthru_endpoint.cc b/test/core/util/passthru_endpoint.cc index 0da0765979..38c23aa978 100644 --- a/test/core/util/passthru_endpoint.cc +++ b/test/core/util/passthru_endpoint.cc @@ -55,7 +55,7 @@ struct passthru_endpoint { static void me_read(grpc_endpoint* ep, grpc_slice_buffer* slices, grpc_closure* cb) { - half* m = (half*)ep; + half* m = reinterpret_cast(ep); gpr_mu_lock(&m->parent->mu); if (m->parent->shutdown) { GRPC_CLOSURE_SCHED( @@ -77,7 +77,7 @@ static half* other_half(half* h) { static void me_write(grpc_endpoint* ep, grpc_slice_buffer* slices, grpc_closure* cb) { - half* m = other_half((half*)ep); + half* m = other_half(reinterpret_cast(ep)); gpr_mu_lock(&m->parent->mu); grpc_error* error = GRPC_ERROR_NONE; gpr_atm_no_barrier_fetch_add(&m->parent->stats->num_writes, (gpr_atm)1); @@ -108,7 +108,7 @@ static void me_delete_from_pollset_set(grpc_endpoint* ep, grpc_pollset_set* pollset) {} static void me_shutdown(grpc_endpoint* ep, grpc_error* why) { - half* m = (half*)ep; + half* m = reinterpret_cast(ep); gpr_mu_lock(&m->parent->mu); m->parent->shutdown = true; if (m->on_read) { @@ -130,7 +130,7 @@ static void me_shutdown(grpc_endpoint* ep, grpc_error* why) { } static void me_destroy(grpc_endpoint* ep) { - passthru_endpoint* p = ((half*)ep)->parent; + passthru_endpoint* p = (reinterpret_cast(ep))->parent; gpr_mu_lock(&p->mu); if (0 == --p->halves) { gpr_mu_unlock(&p->mu); @@ -147,15 +147,15 @@ static void me_destroy(grpc_endpoint* ep) { } static char* me_get_peer(grpc_endpoint* ep) { - passthru_endpoint* p = ((half*)ep)->parent; - return ((half*)ep) == &p->client ? gpr_strdup("fake:mock_client_endpoint") + passthru_endpoint* p = (reinterpret_cast(ep))->parent; + return (reinterpret_cast(ep)) == &p->client ? gpr_strdup("fake:mock_client_endpoint") : gpr_strdup("fake:mock_server_endpoint"); } static int me_get_fd(grpc_endpoint* ep) { return -1; } static grpc_resource_user* me_get_resource_user(grpc_endpoint* ep) { - half* m = (half*)ep; + half* m = reinterpret_cast(ep); return m->resource_user; } @@ -190,7 +190,7 @@ void grpc_passthru_endpoint_create(grpc_endpoint** client, grpc_endpoint** server, grpc_resource_quota* resource_quota, grpc_passthru_endpoint_stats* stats) { - passthru_endpoint* m = (passthru_endpoint*)gpr_malloc(sizeof(*m)); + passthru_endpoint* m = static_cast(gpr_malloc(sizeof(*m))); m->halves = 2; m->shutdown = 0; if (stats == nullptr) { @@ -208,8 +208,8 @@ void grpc_passthru_endpoint_create(grpc_endpoint** client, grpc_passthru_endpoint_stats* grpc_passthru_endpoint_stats_create() { grpc_passthru_endpoint_stats* stats = - (grpc_passthru_endpoint_stats*)gpr_malloc( - sizeof(grpc_passthru_endpoint_stats)); + static_cast(gpr_malloc( + sizeof(grpc_passthru_endpoint_stats))); memset(stats, 0, sizeof(*stats)); gpr_ref_init(&stats->refs, 1); return stats; diff --git a/test/core/util/port.cc b/test/core/util/port.cc index 9d02b673ed..4690727337 100644 --- a/test/core/util/port.cc +++ b/test/core/util/port.cc @@ -76,7 +76,7 @@ static void chose_port(int port) { } num_chosen_ports++; chosen_ports = - (int*)gpr_realloc(chosen_ports, sizeof(int) * num_chosen_ports); + static_cast(gpr_realloc(chosen_ports, sizeof(int) * num_chosen_ports)); chosen_ports[num_chosen_ports - 1] = port; } diff --git a/test/core/util/port_server_client.cc b/test/core/util/port_server_client.cc index 7e76c8063f..886951c20d 100644 --- a/test/core/util/port_server_client.cc +++ b/test/core/util/port_server_client.cc @@ -41,13 +41,13 @@ typedef struct freereq { } freereq; static void destroy_pops_and_shutdown(void* p, grpc_error* error) { - grpc_pollset* pollset = grpc_polling_entity_pollset((grpc_polling_entity*)p); + grpc_pollset* pollset = grpc_polling_entity_pollset(static_cast(p)); grpc_pollset_destroy(pollset); gpr_free(pollset); } static void freed_port_from_server(void* arg, grpc_error* error) { - freereq* pr = (freereq*)arg; + freereq* pr = static_cast(arg); gpr_mu_lock(pr->mu); pr->done = 1; GRPC_LOG_IF_ERROR( @@ -71,7 +71,7 @@ void grpc_free_port_using_server(int port) { memset(&req, 0, sizeof(req)); memset(&rsp, 0, sizeof(rsp)); - grpc_pollset* pollset = (grpc_pollset*)gpr_zalloc(grpc_pollset_size()); + grpc_pollset* pollset = static_cast(gpr_zalloc(grpc_pollset_size())); grpc_pollset_init(pollset, &pr.mu); pr.pops = grpc_polling_entity_create_from_pollset(pollset); shutdown_closure = GRPC_CLOSURE_CREATE(destroy_pops_and_shutdown, &pr.pops, @@ -127,7 +127,7 @@ typedef struct portreq { static void got_port_from_server(void* arg, grpc_error* error) { size_t i; int port = 0; - portreq* pr = (portreq*)arg; + portreq* pr = static_cast(arg); int failed = 0; grpc_httpcli_response* response = &pr->response; @@ -158,7 +158,7 @@ static void got_port_from_server(void* arg, grpc_error* error) { gpr_sleep_until(gpr_time_add( gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_millis( - (int64_t)(1000.0 * (1 + pow(1.3, pr->retries) * rand() / RAND_MAX)), + static_cast(1000.0 * (1 + pow(1.3, pr->retries) * rand() / RAND_MAX)), GPR_TIMESPAN))); pr->retries++; req.host = pr->server; @@ -201,7 +201,7 @@ int grpc_pick_port_using_server(void) { grpc_core::ExecCtx exec_ctx; memset(&pr, 0, sizeof(pr)); memset(&req, 0, sizeof(req)); - grpc_pollset* pollset = (grpc_pollset*)gpr_zalloc(grpc_pollset_size()); + grpc_pollset* pollset = static_cast(gpr_zalloc(grpc_pollset_size())); grpc_pollset_init(pollset, &pr.mu); pr.pops = grpc_polling_entity_create_from_pollset(pollset); shutdown_closure = GRPC_CLOSURE_CREATE(destroy_pops_and_shutdown, &pr.pops, diff --git a/test/core/util/reconnect_server.cc b/test/core/util/reconnect_server.cc index b5a7749385..ea8fee499c 100644 --- a/test/core/util/reconnect_server.cc +++ b/test/core/util/reconnect_server.cc @@ -62,7 +62,7 @@ static void on_connect(void* arg, grpc_endpoint* tcp, gpr_free(acceptor); char* peer; char* last_colon; - reconnect_server* server = (reconnect_server*)arg; + reconnect_server* server = static_cast(arg); gpr_timespec now = gpr_now(GPR_CLOCK_REALTIME); timestamp_list* new_tail; peer = grpc_endpoint_get_peer(tcp); @@ -76,7 +76,7 @@ static void on_connect(void* arg, grpc_endpoint* tcp, } else { if (last_colon == nullptr) { gpr_log(GPR_ERROR, "peer does not contain a ':'"); - } else if (strncmp(server->peer, peer, (size_t)(last_colon - peer)) != + } else if (strncmp(server->peer, peer, static_cast(last_colon - peer)) != 0) { gpr_log(GPR_ERROR, "mismatched peer! %s vs %s", server->peer, peer); } diff --git a/test/core/util/slice_splitter.cc b/test/core/util/slice_splitter.cc index c92fc0affe..e766c1982c 100644 --- a/test/core/util/slice_splitter.cc +++ b/test/core/util/slice_splitter.cc @@ -46,7 +46,7 @@ void grpc_split_slices(grpc_slice_split_mode mode, grpc_slice* src_slices, case GRPC_SLICE_SPLIT_IDENTITY: *dst_slice_count = src_slice_count; *dst_slices = - (grpc_slice*)gpr_malloc(sizeof(grpc_slice) * src_slice_count); + static_cast(gpr_malloc(sizeof(grpc_slice) * src_slice_count)); for (i = 0; i < src_slice_count; i++) { (*dst_slices)[i] = src_slices[i]; grpc_slice_ref((*dst_slices)[i]); @@ -58,7 +58,7 @@ void grpc_split_slices(grpc_slice_split_mode mode, grpc_slice* src_slices, for (i = 0; i < src_slice_count; i++) { length += GRPC_SLICE_LENGTH(src_slices[i]); } - *dst_slices = (grpc_slice*)gpr_malloc(sizeof(grpc_slice)); + *dst_slices = static_cast(gpr_malloc(sizeof(grpc_slice))); **dst_slices = grpc_slice_malloc(length); length = 0; for (i = 0; i < src_slice_count; i++) { @@ -74,7 +74,7 @@ void grpc_split_slices(grpc_slice_split_mode mode, grpc_slice* src_slices, length += GRPC_SLICE_LENGTH(src_slices[i]); } *dst_slice_count = length; - *dst_slices = (grpc_slice*)gpr_malloc(sizeof(grpc_slice) * length); + *dst_slices = static_cast(gpr_malloc(sizeof(grpc_slice) * length)); length = 0; for (i = 0; i < src_slice_count; i++) { for (j = 0; j < GRPC_SLICE_LENGTH(src_slices[i]); j++) { @@ -114,7 +114,7 @@ grpc_slice grpc_slice_merge(grpc_slice* slices, size_t nslices) { for (i = 0; i < nslices; i++) { if (GRPC_SLICE_LENGTH(slices[i]) + length > capacity) { capacity = GPR_MAX(capacity * 2, GRPC_SLICE_LENGTH(slices[i]) + length); - out = (uint8_t*)gpr_realloc(out, capacity); + out = static_cast(gpr_realloc(out, capacity)); } memcpy(out + length, GRPC_SLICE_START_PTR(slices[i]), GRPC_SLICE_LENGTH(slices[i])); diff --git a/test/core/util/subprocess_posix.cc b/test/core/util/subprocess_posix.cc index 0f6c99731f..bb42ccbdeb 100644 --- a/test/core/util/subprocess_posix.cc +++ b/test/core/util/subprocess_posix.cc @@ -52,8 +52,8 @@ gpr_subprocess* gpr_subprocess_create(int argc, const char** argv) { if (pid == -1) { return nullptr; } else if (pid == 0) { - exec_args = (char**)gpr_malloc(((size_t)argc + 1) * sizeof(char*)); - memcpy(exec_args, argv, (size_t)argc * sizeof(char*)); + exec_args = static_cast(gpr_malloc((static_cast(argc) + 1) * sizeof(char*))); + memcpy(exec_args, argv, static_cast(argc) * sizeof(char*)); exec_args[argc] = nullptr; execv(exec_args[0], exec_args); /* if we reach here, an error has occurred */ @@ -61,7 +61,7 @@ gpr_subprocess* gpr_subprocess_create(int argc, const char** argv) { _exit(1); return nullptr; } else { - r = (gpr_subprocess*)gpr_zalloc(sizeof(gpr_subprocess)); + r = static_cast(gpr_zalloc(sizeof(gpr_subprocess))); r->pid = pid; return r; } diff --git a/test/core/util/test_config.cc b/test/core/util/test_config.cc index e381be6842..5c01cfd070 100644 --- a/test/core/util/test_config.cc +++ b/test/core/util/test_config.cc @@ -36,7 +36,7 @@ int64_t g_poller_slowdown_factor = 1; #if GPR_GETPID_IN_UNISTD_H #include -static unsigned seed(void) { return (unsigned)getpid(); } +static unsigned seed(void) { return static_cast(getpid()); } #endif #if GPR_GETPID_IN_PROCESS_H @@ -264,7 +264,7 @@ static void install_crash_handler() { ss.ss_size = sizeof(g_alt_stack); ss.ss_sp = g_alt_stack; GPR_ASSERT(sigaltstack(&ss, nullptr) == 0); - sa.sa_flags = (int)(SA_SIGINFO | SA_ONSTACK | SA_RESETHAND); + sa.sa_flags = static_cast(SA_SIGINFO | SA_ONSTACK | SA_RESETHAND); sa.sa_sigaction = crash_handler; GPR_ASSERT(sigaction(SIGILL, &sa, nullptr) == 0); GPR_ASSERT(sigaction(SIGABRT, &sa, nullptr) == 0); @@ -365,14 +365,14 @@ int64_t grpc_test_slowdown_factor() { gpr_timespec grpc_timeout_seconds_to_deadline(int64_t time_s) { return gpr_time_add( gpr_now(GPR_CLOCK_MONOTONIC), - gpr_time_from_millis(grpc_test_slowdown_factor() * (int64_t)1e3 * time_s, + gpr_time_from_millis(grpc_test_slowdown_factor() * static_cast(1e3) * time_s, GPR_TIMESPAN)); } gpr_timespec grpc_timeout_milliseconds_to_deadline(int64_t time_ms) { return gpr_time_add( gpr_now(GPR_CLOCK_MONOTONIC), - gpr_time_from_micros(grpc_test_slowdown_factor() * (int64_t)1e3 * time_ms, + gpr_time_from_micros(grpc_test_slowdown_factor() * static_cast(1e3) * time_ms, GPR_TIMESPAN)); } diff --git a/test/core/util/test_tcp_server.cc b/test/core/util/test_tcp_server.cc index b1b5297f29..1216934630 100644 --- a/test/core/util/test_tcp_server.cc +++ b/test/core/util/test_tcp_server.cc @@ -54,12 +54,12 @@ void test_tcp_server_init(test_tcp_server* server, void test_tcp_server_start(test_tcp_server* server, int port) { grpc_resolved_address resolved_addr; - struct sockaddr_in* addr = (struct sockaddr_in*)resolved_addr.addr; + struct sockaddr_in* addr = reinterpret_cast(resolved_addr.addr); int port_added; grpc_core::ExecCtx exec_ctx; addr->sin_family = AF_INET; - addr->sin_port = htons((uint16_t)port); + addr->sin_port = htons(static_cast(port)); memset(&addr->sin_addr, 0, sizeof(addr->sin_addr)); grpc_error* error = grpc_tcp_server_create(&server->shutdown_complete, diff --git a/test/core/util/trickle_endpoint.cc b/test/core/util/trickle_endpoint.cc index 54e1cf19c9..87a8d9c216 100644 --- a/test/core/util/trickle_endpoint.cc +++ b/test/core/util/trickle_endpoint.cc @@ -48,7 +48,7 @@ typedef struct { static void te_read(grpc_endpoint* ep, grpc_slice_buffer* slices, grpc_closure* cb) { - trickle_endpoint* te = (trickle_endpoint*)ep; + trickle_endpoint* te = reinterpret_cast(ep); grpc_endpoint_read(te->wrapped, slices, cb); } @@ -63,7 +63,7 @@ static void maybe_call_write_cb_locked(trickle_endpoint* te) { static void te_write(grpc_endpoint* ep, grpc_slice_buffer* slices, grpc_closure* cb) { - trickle_endpoint* te = (trickle_endpoint*)ep; + trickle_endpoint* te = reinterpret_cast(ep); gpr_mu_lock(&te->mu); GPR_ASSERT(te->write_cb == nullptr); if (te->write_buffer.length == 0) { @@ -79,24 +79,24 @@ static void te_write(grpc_endpoint* ep, grpc_slice_buffer* slices, } static void te_add_to_pollset(grpc_endpoint* ep, grpc_pollset* pollset) { - trickle_endpoint* te = (trickle_endpoint*)ep; + trickle_endpoint* te = reinterpret_cast(ep); grpc_endpoint_add_to_pollset(te->wrapped, pollset); } static void te_add_to_pollset_set(grpc_endpoint* ep, grpc_pollset_set* pollset_set) { - trickle_endpoint* te = (trickle_endpoint*)ep; + trickle_endpoint* te = reinterpret_cast(ep); grpc_endpoint_add_to_pollset_set(te->wrapped, pollset_set); } static void te_delete_from_pollset_set(grpc_endpoint* ep, grpc_pollset_set* pollset_set) { - trickle_endpoint* te = (trickle_endpoint*)ep; + trickle_endpoint* te = reinterpret_cast(ep); grpc_endpoint_delete_from_pollset_set(te->wrapped, pollset_set); } static void te_shutdown(grpc_endpoint* ep, grpc_error* why) { - trickle_endpoint* te = (trickle_endpoint*)ep; + trickle_endpoint* te = reinterpret_cast(ep); gpr_mu_lock(&te->mu); if (te->error == GRPC_ERROR_NONE) { te->error = GRPC_ERROR_REF(why); @@ -107,7 +107,7 @@ static void te_shutdown(grpc_endpoint* ep, grpc_error* why) { } static void te_destroy(grpc_endpoint* ep) { - trickle_endpoint* te = (trickle_endpoint*)ep; + trickle_endpoint* te = reinterpret_cast(ep); grpc_endpoint_destroy(te->wrapped); gpr_mu_destroy(&te->mu); grpc_slice_buffer_destroy_internal(&te->write_buffer); @@ -117,22 +117,22 @@ static void te_destroy(grpc_endpoint* ep) { } static grpc_resource_user* te_get_resource_user(grpc_endpoint* ep) { - trickle_endpoint* te = (trickle_endpoint*)ep; + trickle_endpoint* te = reinterpret_cast(ep); return grpc_endpoint_get_resource_user(te->wrapped); } static char* te_get_peer(grpc_endpoint* ep) { - trickle_endpoint* te = (trickle_endpoint*)ep; + trickle_endpoint* te = reinterpret_cast(ep); return grpc_endpoint_get_peer(te->wrapped); } static int te_get_fd(grpc_endpoint* ep) { - trickle_endpoint* te = (trickle_endpoint*)ep; + trickle_endpoint* te = reinterpret_cast(ep); return grpc_endpoint_get_fd(te->wrapped); } static void te_finish_write(void* arg, grpc_error* error) { - trickle_endpoint* te = (trickle_endpoint*)arg; + trickle_endpoint* te = static_cast(arg); gpr_mu_lock(&te->mu); te->writing = false; grpc_slice_buffer_reset_and_unref(&te->writing_buffer); @@ -152,7 +152,7 @@ static const grpc_endpoint_vtable vtable = {te_read, grpc_endpoint* grpc_trickle_endpoint_create(grpc_endpoint* wrap, double bytes_per_second) { - trickle_endpoint* te = (trickle_endpoint*)gpr_malloc(sizeof(*te)); + trickle_endpoint* te = static_cast(gpr_malloc(sizeof(*te))); te->base.vtable = &vtable; te->wrapped = wrap; te->bytes_per_second = bytes_per_second; @@ -166,16 +166,16 @@ grpc_endpoint* grpc_trickle_endpoint_create(grpc_endpoint* wrap, } static double ts2dbl(gpr_timespec s) { - return (double)s.tv_sec + 1e-9 * (double)s.tv_nsec; + return static_cast(s.tv_sec) + 1e-9 * static_cast(s.tv_nsec); } size_t grpc_trickle_endpoint_trickle(grpc_endpoint* ep) { - trickle_endpoint* te = (trickle_endpoint*)ep; + trickle_endpoint* te = reinterpret_cast(ep); gpr_mu_lock(&te->mu); if (!te->writing && te->write_buffer.length > 0) { gpr_timespec now = gpr_now(GPR_CLOCK_MONOTONIC); double elapsed = ts2dbl(gpr_time_sub(now, te->last_write)); - size_t bytes = (size_t)(te->bytes_per_second * elapsed); + size_t bytes = static_cast(te->bytes_per_second * elapsed); // gpr_log(GPR_DEBUG, "%lf elapsed --> %" PRIdPTR " bytes", elapsed, bytes); if (bytes > 0) { grpc_slice_buffer_move_first(&te->write_buffer, @@ -195,7 +195,7 @@ size_t grpc_trickle_endpoint_trickle(grpc_endpoint* ep) { } size_t grpc_trickle_get_backlog(grpc_endpoint* ep) { - trickle_endpoint* te = (trickle_endpoint*)ep; + trickle_endpoint* te = reinterpret_cast(ep); gpr_mu_lock(&te->mu); size_t backlog = te->write_buffer.length; gpr_mu_unlock(&te->mu); -- cgit v1.2.3