Skip to content

Commit

Permalink
Enable clang-tidy as a sanity check, fix up all known failures
Browse files Browse the repository at this point in the history
  • Loading branch information
ctiller committed Nov 10, 2017
1 parent e77b3c3 commit 4ac2b8e
Show file tree
Hide file tree
Showing 290 changed files with 5,504 additions and 6,766 deletions.
5 changes: 5 additions & 0 deletions .clang_complete
Expand Up @@ -10,3 +10,8 @@
-Ithird_party/zlib
-Ithird_party/protobuf/src
-Ithird_party/abseil-cpp
-Ithird_party/cares/cares
-Ithird_party/cares
-Ithird_party/googletest/googletest/include
-Ithird_party/googletest/googlemock/include

Expand Up @@ -449,8 +449,8 @@ static bool is_server_valid(const grpc_grpclb_server* server, size_t idx,

/* vtable for LB tokens in grpc_lb_addresses. */
static void* lb_token_copy(void* token) {
return token == NULL
? NULL
return token == nullptr
? nullptr
: (void*)GRPC_MDELEM_REF(grpc_mdelem{(uintptr_t)token}).payload;
}
static void lb_token_destroy(grpc_exec_ctx* exec_ctx, void* token) {
Expand Down Expand Up @@ -563,7 +563,7 @@ static grpc_lb_addresses* extract_backend_addresses_locked(
const grpc_resolved_address* addr = &addresses->addresses[i].address;
grpc_lb_addresses_set_address(backend_addresses, num_copied, &addr->addr,
addr->len, false /* is_balancer */,
NULL /* balancer_name */,
nullptr /* balancer_name */,
(void*)GRPC_MDELEM_LB_TOKEN_EMPTY.payload);
++num_copied;
}
Expand Down
Expand Up @@ -19,6 +19,7 @@
#ifndef GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_RESOLVER_DNS_C_ARES_GRPC_ARES_EV_DRIVER_H
#define GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_RESOLVER_DNS_C_ARES_GRPC_ARES_EV_DRIVER_H

#include <ares.h>
#include "src/core/lib/iomgr/exec_ctx.h"
#include "src/core/lib/iomgr/pollset_set.h"

Expand Down
Expand Up @@ -285,7 +285,7 @@ static void grpc_ares_notify_on_event_locked(grpc_exec_ctx* exec_ctx,
ARES_GETSOCK_WRITABLE(socks_bitmask, i)) {
fd_node* fdn = pop_fd_node(&ev_driver->fds, socks[i]);
// Create a new fd_node if sock[i] is not in the fd_node list.
if (fdn == NULL) {
if (fdn == nullptr) {
char* fd_name;
gpr_asprintf(&fd_name, "ares_ev_driver-%" PRIuPTR, i);
fdn = (fd_node*)gpr_malloc(sizeof(fd_node));
Expand Down
Expand Up @@ -297,7 +297,7 @@ static void on_txt_done_cb(void* arg, int status, int timeouts,
*r->service_config_json_out = (char*)gpr_malloc(service_config_len + 1);
memcpy(*r->service_config_json_out, result->txt + prefix_len,
service_config_len);
for (result = result->next; result != NULL && !result->record_start;
for (result = result->next; result != nullptr && !result->record_start;
result = result->next) {
*r->service_config_json_out = (char*)gpr_realloc(
*r->service_config_json_out, service_config_len + result->length + 1);
Expand Down Expand Up @@ -334,7 +334,7 @@ static grpc_ares_request* grpc_dns_lookup_ares_impl(
grpc_error* error = GRPC_ERROR_NONE;
grpc_ares_hostbyname_request* hr = nullptr;
grpc_ares_request* r = nullptr;
ares_channel* channel = NULL;
ares_channel* channel = nullptr;
/* TODO(zyc): Enable tracing after #9603 is checked in */
/* if (grpc_dns_trace) {
gpr_log(GPR_DEBUG, "resolve_address (blocking): name=%s, default_port=%s",
Expand Down
4 changes: 2 additions & 2 deletions src/core/ext/transport/chttp2/transport/chttp2_transport.cc
Expand Up @@ -575,7 +575,7 @@ static void init_transport(grpc_exec_ctx* exec_ctx, grpc_chttp2_transport* t,
schedule_bdp_ping_locked(exec_ctx, t);

grpc_chttp2_act_on_flowctl_action(
exec_ctx, t->flow_control->PeriodicUpdate(exec_ctx), t, NULL);
exec_ctx, t->flow_control->PeriodicUpdate(exec_ctx), t, nullptr);
}

grpc_chttp2_initiate_write(exec_ctx, t,
Expand Down Expand Up @@ -2569,7 +2569,7 @@ static void read_action_locked(grpc_exec_ctx* exec_ctx, void* tp,
grpc_endpoint_read(exec_ctx, t->ep, &t->read_buffer,
&t->read_action_locked);
grpc_chttp2_act_on_flowctl_action(exec_ctx, t->flow_control->MakeAction(),
t, NULL);
t, nullptr);
GRPC_CHTTP2_UNREF_TRANSPORT(exec_ctx, t, "keep_reading");
} else {
GRPC_CHTTP2_UNREF_TRANSPORT(exec_ctx, t, "reading_action");
Expand Down
2 changes: 1 addition & 1 deletion src/core/ext/transport/chttp2/transport/flow_control.h
Expand Up @@ -41,7 +41,7 @@ class TrickledCHTTP2; // to make this a friend
namespace grpc_core {
namespace chttp2 {

static constexpr uint32_t;;;;;;;;;;;;; kDefaultWindow = 65535;
static constexpr uint32_t kDefaultWindow = 65535;

class TransportFlowControl;
class StreamFlowControl;
Expand Down
1 change: 1 addition & 0 deletions src/core/ext/transport/chttp2/transport/stream_map.cc
Expand Up @@ -145,6 +145,7 @@ void* grpc_chttp2_stream_map_rand(grpc_chttp2_stream_map* map) {
if (map->free != 0) {
map->count = compact(map->keys, map->values, map->count);
map->free = 0;
GPR_ASSERT(map->count > 0);
}
return map->values[((size_t)rand()) % map->count];
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/ext/transport/chttp2/transport/writing.cc
Expand Up @@ -397,7 +397,7 @@ class StreamWriteContext {
GRPC_CHTTP2_IF_TRACING(
gpr_log(GPR_DEBUG, "W:%p %s[%d] im-(sent,send)=(%d,%d) announce=%d", t_,
t_->is_client ? "CLIENT" : "SERVER", s->id,
s->sent_initial_metadata, s->send_initial_metadata != NULL,
s->sent_initial_metadata, s->send_initial_metadata != nullptr,
(int)(s->flow_control->local_window_delta() -
s->flow_control->announced_window_delta())));
}
Expand Down
9 changes: 8 additions & 1 deletion src/core/lib/iomgr/error.h
Expand Up @@ -24,6 +24,7 @@

#include <grpc/slice.h>
#include <grpc/status.h>
#include <grpc/support/log.h>
#include <grpc/support/time.h>

#include "src/core/lib/debug/trace.h"
Expand Down Expand Up @@ -184,9 +185,15 @@ grpc_error* grpc_error_add_child(grpc_error* src,
grpc_error* child) GRPC_MUST_USE_RESULT;
grpc_error* grpc_os_error(const char* file, int line, int err,
const char* call_name) GRPC_MUST_USE_RESULT;

inline grpc_error* grpc_assert_never_ok(grpc_error* error) {
GPR_ASSERT(error != GRPC_ERROR_NONE);
return error;
}

/// create an error associated with errno!=0 (an 'operating system' error)
#define GRPC_OS_ERROR(err, call_name) \
grpc_os_error(__FILE__, __LINE__, err, call_name)
grpc_assert_never_ok(grpc_os_error(__FILE__, __LINE__, err, call_name))
grpc_error* grpc_wsa_error(const char* file, int line, int err,
const char* call_name) GRPC_MUST_USE_RESULT;
/// windows only: create an error associated with WSAGetLastError()!=0
Expand Down
1 change: 1 addition & 0 deletions src/core/lib/iomgr/error_internal.h
Expand Up @@ -23,6 +23,7 @@
#include <stdbool.h> // TODO, do we need this?

#include <grpc/support/sync.h>
#include "src/core/lib/iomgr/error.h"

#ifdef __cplusplus
extern "C" {
Expand Down
5 changes: 5 additions & 0 deletions src/core/lib/iomgr/iocp_windows.h
Expand Up @@ -21,6 +21,10 @@

#include <grpc/support/sync.h>

#include "src/core/lib/iomgr/port.h"

#ifdef GRPC_WINSOCK_SOCKET

#include "src/core/lib/iomgr/socket_windows.h"

#ifdef __cplusplus
Expand All @@ -45,4 +49,5 @@ void grpc_iocp_add_socket(grpc_winsocket*);
}
#endif

#endif /* GRPC_WINSOCK_SOCKET */
#endif /* GRPC_CORE_LIB_IOMGR_IOCP_WINDOWS_H */
2 changes: 1 addition & 1 deletion src/core/lib/iomgr/lockfree_event.h
Expand Up @@ -25,7 +25,7 @@

#include "src/core/lib/iomgr/exec_ctx.h"

namespace grpc_core; {
namespace grpc_core {

class LockfreeEvent {
public:
Expand Down
4 changes: 4 additions & 0 deletions src/core/lib/iomgr/pollset_windows.h
Expand Up @@ -21,6 +21,9 @@

#include <grpc/support/sync.h>

#include "src/core/lib/iomgr/port.h"

#ifdef GRPC_WINSOCK_SOCKET
#include "src/core/lib/iomgr/socket_windows.h"

#ifdef __cplusplus
Expand Down Expand Up @@ -68,4 +71,5 @@ void grpc_pollset_global_shutdown(void);
}
#endif

#endif /* GRPC_WINSOCK_SOCKET */
#endif /* GRPC_CORE_LIB_IOMGR_POLLSET_WINDOWS_H */
5 changes: 5 additions & 0 deletions src/core/lib/iomgr/sockaddr_windows.h
Expand Up @@ -19,10 +19,15 @@
#ifndef GRPC_CORE_LIB_IOMGR_SOCKADDR_WINDOWS_H
#define GRPC_CORE_LIB_IOMGR_SOCKADDR_WINDOWS_H

#include "src/core/lib/iomgr/port.h"

#ifdef GRPC_WINSOCK_SOCKET

#include <winsock2.h>
#include <ws2tcpip.h>

// must be included after the above
#include <mswsock.h>

#endif /* GRPC_WINSOCK_SOCKET */
#endif /* GRPC_CORE_LIB_IOMGR_SOCKADDR_WINDOWS_H */
4 changes: 4 additions & 0 deletions src/core/lib/iomgr/socket_windows.h
Expand Up @@ -20,6 +20,9 @@
#define GRPC_CORE_LIB_IOMGR_SOCKET_WINDOWS_H

#include <grpc/support/port_platform.h>
#include "src/core/lib/iomgr/port.h"

#ifdef GRPC_WINSOCK_SOCKET
#include <winsock2.h>

#include <grpc/support/atm.h>
Expand Down Expand Up @@ -115,4 +118,5 @@ void grpc_socket_become_ready(grpc_exec_ctx* exec_ctx,
}
#endif

#endif /* GRPC_WINSOCK_SOCKET */
#endif /* GRPC_CORE_LIB_IOMGR_SOCKET_WINDOWS_H */
6 changes: 6 additions & 0 deletions src/core/lib/iomgr/tcp_uv.h
Expand Up @@ -32,6 +32,10 @@
#include "src/core/lib/debug/trace.h"
#include "src/core/lib/iomgr/endpoint.h"

#include "src/core/lib/iomgr/port.h"

#ifdef GRPC_UV

#include <uv.h>

extern grpc_tracer_flag grpc_tcp_trace;
Expand All @@ -50,4 +54,6 @@ grpc_endpoint* grpc_tcp_create(uv_tcp_t* handle,
}
#endif

#endif /* GRPC_UV */

#endif /* GRPC_CORE_LIB_IOMGR_TCP_UV_H */
4 changes: 4 additions & 0 deletions src/core/lib/iomgr/tcp_windows.h
Expand Up @@ -29,6 +29,9 @@
otherwise specified.
*/

#include "src/core/lib/iomgr/port.h"

#ifdef GRPC_WINSOCK_SOCKET
#include "src/core/lib/iomgr/endpoint.h"
#include "src/core/lib/iomgr/socket_windows.h"

Expand All @@ -49,4 +52,5 @@ grpc_error* grpc_tcp_prepare_socket(SOCKET sock);
}
#endif

#endif /* GRPC_WINSOCK_SOCKET */
#endif /* GRPC_CORE_LIB_IOMGR_TCP_WINDOWS_H */
1 change: 1 addition & 0 deletions src/core/lib/iomgr/udp_server.cc
Expand Up @@ -508,6 +508,7 @@ int grpc_udp_server_get_fd(grpc_udp_server* s, unsigned port_index) {
for (sp = s->head; sp && port_index != 0; sp = sp->next) {
--port_index;
}
GPR_ASSERT(sp); // if this fails, our check earlier was bogus
return sp->fd;
}

Expand Down
5 changes: 3 additions & 2 deletions src/core/lib/iomgr/unix_sockets_posix.cc
Expand Up @@ -39,7 +39,8 @@ void grpc_create_socketpair_if_unix(int sv[2]) {
grpc_error* grpc_resolve_unix_domain_address(const char* name,
grpc_resolved_addresses** addrs) {
struct sockaddr_un* un;
if (strlen(name) > GPR_ARRAY_SIZE(((struct sockaddr_un*)nullptr)->sun_path) - 1) {
if (strlen(name) >
GPR_ARRAY_SIZE(((struct sockaddr_un*)nullptr)->sun_path) - 1) {
char* err_msg;
grpc_error* err;
gpr_asprintf(&err_msg,
Expand All @@ -56,7 +57,7 @@ grpc_error* grpc_resolve_unix_domain_address(const char* name,
(grpc_resolved_address*)gpr_malloc(sizeof(grpc_resolved_address));
un = (struct sockaddr_un*)(*addrs)->addrs->addr;
un->sun_family = AF_UNIX;
strcpy(un->sun_path, name);
strncpy(un->sun_path, name, sizeof(un->sun_path));
(*addrs)->addrs->len = strlen(un->sun_path) + sizeof(un->sun_family) + 1;
return GRPC_ERROR_NONE;
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/lib/support/atomic_with_atm.h
Expand Up @@ -21,7 +21,7 @@

#include <grpc/support/atm.h>

namespace grpc_core;; {
namespace grpc_core {

enum MemoryOrderRelaxed { memory_order_relaxed };

Expand Down
2 changes: 1 addition & 1 deletion src/core/lib/support/memory.h
Expand Up @@ -76,7 +76,7 @@ class Allocator {
pointer address(reference x) const { return &x; }
const_pointer address(const_reference x) const { return &x; }
pointer allocate(std::size_t n,
std::allocator<void>::const_pointer hint = 0) {
std::allocator<void>::const_pointer hint = nullptr) {
return static_cast<pointer>(gpr_malloc(n * sizeof(T)));
}
void deallocate(T* p, std::size_t n) { gpr_free(p); }
Expand Down
8 changes: 4 additions & 4 deletions src/core/lib/surface/channel.cc
Expand Up @@ -302,10 +302,10 @@ grpc_call* grpc_channel_create_call(grpc_channel* channel,
GPR_ASSERT(!reserved);
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
grpc_call* call = grpc_channel_create_call_internal(
&exec_ctx, channel, parent_call, propagation_mask, cq, NULL,
&exec_ctx, channel, parent_call, propagation_mask, cq, nullptr,
grpc_mdelem_from_slices(&exec_ctx, GRPC_MDSTR_PATH,
grpc_slice_ref_internal(method)),
host != NULL ? grpc_mdelem_from_slices(&exec_ctx, GRPC_MDSTR_AUTHORITY,
host != nullptr ? grpc_mdelem_from_slices(&exec_ctx, GRPC_MDSTR_AUTHORITY,
grpc_slice_ref_internal(*host))
: GRPC_MDNULL,
grpc_timespec_to_millis_round_up(deadline));
Expand All @@ -319,10 +319,10 @@ grpc_call* grpc_channel_create_pollset_set_call(
const grpc_slice* host, grpc_millis deadline, void* reserved) {
GPR_ASSERT(!reserved);
return grpc_channel_create_call_internal(
exec_ctx, channel, parent_call, propagation_mask, NULL, pollset_set,
exec_ctx, channel, parent_call, propagation_mask, nullptr, pollset_set,
grpc_mdelem_from_slices(exec_ctx, GRPC_MDSTR_PATH,
grpc_slice_ref_internal(method)),
host != NULL ? grpc_mdelem_from_slices(exec_ctx, GRPC_MDSTR_AUTHORITY,
host != nullptr ? grpc_mdelem_from_slices(exec_ctx, GRPC_MDSTR_AUTHORITY,
grpc_slice_ref_internal(*host))
: GRPC_MDNULL,
deadline);
Expand Down
2 changes: 1 addition & 1 deletion src/core/lib/transport/bdp_estimator.h
Expand Up @@ -33,7 +33,7 @@

extern grpc_tracer_flag grpc_bdp_estimator_trace;

namespace grpc_core; {
namespace grpc_core {

class BdpEstimator {
public:
Expand Down
2 changes: 0 additions & 2 deletions src/core/lib/transport/error_utils.cc
Expand Up @@ -90,8 +90,6 @@ void grpc_error_get_status(grpc_exec_ctx* exec_ctx, grpc_error* error,
}
}
}

if (found_error == nullptr) found_error = error;
}

bool grpc_error_has_clear_grpc_status(grpc_error* error) {
Expand Down
2 changes: 1 addition & 1 deletion src/core/lib/transport/transport_op_string.cc
Expand Up @@ -189,7 +189,7 @@ char* grpc_transport_op_string(grpc_transport_op* op) {

if (op->send_ping != nullptr) {
if (!first) gpr_strvec_add(&b, gpr_strdup(" "));
first = false;
// first = false;
gpr_strvec_add(&b, gpr_strdup("SEND_PING"));
}

Expand Down

0 comments on commit 4ac2b8e

Please sign in to comment.