Skip to content

Commit f8a4aae

Browse files
committed
Fix all instances of bugprone-undefined-memory-manipulation
1 parent 92d1b5c commit f8a4aae

File tree

7 files changed

+30
-15
lines changed

7 files changed

+30
-15
lines changed

.clang-tidy

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
2-
Checks: 'modernize-use-nullptr,google-build-namespaces,google-build-explicit-make-pair,readability-function-size,performance-*'
3-
WarningsAsErrors: 'modernize-use-nullptr,google-build-namespaces,google-build-explicit-make-pair,readability-function-size,performance-*'
2+
Checks: 'modernize-use-nullptr,google-build-namespaces,google-build-explicit-make-pair,readability-function-size,performance-*,bugprone-*'
3+
WarningsAsErrors: 'modernize-use-nullptr,google-build-namespaces,google-build-explicit-make-pair,readability-function-size,performance-*,bugprone-*'
44
CheckOptions:
55
- key: readability-function-size.StatementThreshold
66
value: '450'

src/core/ext/filters/client_channel/client_channel.cc

-1
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,6 @@ get_service_config_from_resolver_result_locked(channel_data* chand) {
457457
grpc_uri* uri = grpc_uri_parse(server_uri, true);
458458
GPR_ASSERT(uri->path[0] != '\0');
459459
service_config_parsing_state parsing_state;
460-
memset(&parsing_state, 0, sizeof(parsing_state));
461460
parsing_state.server_name =
462461
uri->path[0] == '/' ? uri->path + 1 : uri->path;
463462
service_config->ParseGlobalParams(parse_retry_throttle_params,

src/core/lib/surface/channel.cc

-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ grpc_channel* grpc_channel_create_with_builder(
100100
return channel;
101101
}
102102

103-
memset(channel, 0, sizeof(*channel));
104103
channel->target = target;
105104
channel->is_client = grpc_channel_stack_type_is_client(channel_stack_type);
106105
size_t channel_tracer_max_nodes = 0; // default to off

src/core/tsi/alts_transport_security.cc

+3-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ void grpc_tsi_alts_signal_for_cq_destroy() {
4545
}
4646

4747
void grpc_tsi_alts_init() {
48-
memset(&g_alts_resource, 0, sizeof(alts_shared_resource));
48+
g_alts_resource.channel = nullptr;
49+
g_alts_resource.cq = nullptr;
50+
g_alts_resource.is_cq_drained = false;
4951
gpr_mu_init(&g_alts_resource.mu);
5052
gpr_cv_init(&g_alts_resource.cv);
5153
}
File renamed without changes.

test/core/end2end/fixtures/http_proxy_fixture.cc

+12-6
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,16 @@
5252
#include "test/core/util/port.h"
5353

5454
struct grpc_end2end_http_proxy {
55+
grpc_end2end_http_proxy()
56+
: proxy_name(nullptr),
57+
server(nullptr),
58+
channel_args(nullptr),
59+
mu(nullptr),
60+
pollset(nullptr),
61+
combiner(nullptr) {
62+
gpr_ref_init(&users, 1);
63+
combiner = grpc_combiner_create();
64+
}
5565
char* proxy_name;
5666
grpc_core::Thread thd;
5767
grpc_tcp_server* server;
@@ -519,11 +529,7 @@ static void thread_main(void* arg) {
519529
grpc_end2end_http_proxy* grpc_end2end_http_proxy_create(
520530
grpc_channel_args* args) {
521531
grpc_core::ExecCtx exec_ctx;
522-
grpc_end2end_http_proxy* proxy =
523-
static_cast<grpc_end2end_http_proxy*>(gpr_malloc(sizeof(*proxy)));
524-
memset(proxy, 0, sizeof(*proxy));
525-
proxy->combiner = grpc_combiner_create();
526-
gpr_ref_init(&proxy->users, 1);
532+
grpc_end2end_http_proxy* proxy = grpc_core::New<grpc_end2end_http_proxy>();
527533
// Construct proxy address.
528534
const int proxy_port = grpc_pick_unused_port_or_die();
529535
gpr_join_host_port(&proxy->proxy_name, "localhost", proxy_port);
@@ -573,7 +579,7 @@ void grpc_end2end_http_proxy_destroy(grpc_end2end_http_proxy* proxy) {
573579
GRPC_CLOSURE_CREATE(destroy_pollset, proxy->pollset,
574580
grpc_schedule_on_exec_ctx));
575581
GRPC_COMBINER_UNREF(proxy->combiner, "test");
576-
gpr_free(proxy);
582+
grpc_core::Delete(proxy);
577583
}
578584

579585
const char* grpc_end2end_http_proxy_get_proxy_name(

test/core/end2end/fixtures/proxy.cc

+13-4
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,17 @@
3030
#include "test/core/util/port.h"
3131

3232
struct grpc_end2end_proxy {
33+
grpc_end2end_proxy()
34+
: proxy_port(nullptr),
35+
server_port(nullptr),
36+
cq(nullptr),
37+
server(nullptr),
38+
client(nullptr),
39+
shutdown(false),
40+
new_call(nullptr) {
41+
memset(&new_call_details, 0, sizeof(new_call_details));
42+
memset(&new_call_metadata, 0, sizeof(new_call_metadata));
43+
}
3344
grpc_core::Thread thd;
3445
char* proxy_port;
3546
char* server_port;
@@ -79,9 +90,7 @@ grpc_end2end_proxy* grpc_end2end_proxy_create(const grpc_end2end_proxy_def* def,
7990
int proxy_port = grpc_pick_unused_port_or_die();
8091
int server_port = grpc_pick_unused_port_or_die();
8192

82-
grpc_end2end_proxy* proxy =
83-
static_cast<grpc_end2end_proxy*>(gpr_malloc(sizeof(*proxy)));
84-
memset(proxy, 0, sizeof(*proxy));
93+
grpc_end2end_proxy* proxy = grpc_core::New<grpc_end2end_proxy>();
8594

8695
gpr_join_host_port(&proxy->proxy_port, "localhost", proxy_port);
8796
gpr_join_host_port(&proxy->server_port, "localhost", server_port);
@@ -128,7 +137,7 @@ void grpc_end2end_proxy_destroy(grpc_end2end_proxy* proxy) {
128137
grpc_channel_destroy(proxy->client);
129138
grpc_completion_queue_destroy(proxy->cq);
130139
grpc_call_details_destroy(&proxy->new_call_details);
131-
gpr_free(proxy);
140+
grpc_core::Delete(proxy);
132141
}
133142

134143
static void unrefpc(proxy_call* pc, const char* reason) {

0 commit comments

Comments
 (0)