Merge pull request #19198 from mehrdada/strncpy-gcc-warning

Put strncpy in parens to silence GCC warning
pull/19203/head
Juanli Shen 6 years ago committed by GitHub
commit 7fce9da88f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.cc
  2. 8
      src/core/ext/filters/client_channel/lb_policy/xds/xds_load_balancer_api.cc

@ -67,8 +67,12 @@ grpc_grpclb_request* grpc_grpclb_request_create(const char* lb_service_name) {
req->has_client_stats = false;
req->has_initial_request = true;
req->initial_request.has_name = true;
strncpy(req->initial_request.name, lb_service_name,
GRPC_GRPCLB_SERVICE_NAME_MAX_LENGTH);
// GCC warns (-Wstringop-truncation) because the destination
// buffer size is identical to max-size, leading to a potential
// char[] with no null terminator. nanopb can handle it fine,
// and parantheses around strncpy silence that compiler warning.
(strncpy(req->initial_request.name, lb_service_name,
GRPC_GRPCLB_SERVICE_NAME_MAX_LENGTH));
return req;
}

@ -67,8 +67,12 @@ xds_grpclb_request* xds_grpclb_request_create(const char* lb_service_name) {
req->has_client_stats = false;
req->has_initial_request = true;
req->initial_request.has_name = true;
strncpy(req->initial_request.name, lb_service_name,
XDS_SERVICE_NAME_MAX_LENGTH);
// GCC warns (-Wstringop-truncation) because the destination
// buffer size is identical to max-size, leading to a potential
// char[] with no null terminator. nanopb can handle it fine,
// and parantheses around strncpy silence that compiler warning.
(strncpy(req->initial_request.name, lb_service_name,
XDS_SERVICE_NAME_MAX_LENGTH));
return req;
}

Loading…
Cancel
Save