Enable -Wconversion

pull/3322/head
Craig Tiller 9 years ago
parent 2ed498151d
commit 6a6b36c503
  1. 9
      Makefile
  2. 5
      src/core/channel/compress_filter.c
  3. 4
      src/core/client_config/resolvers/sockaddr_resolver.c
  4. 6
      src/core/iomgr/alarm.c
  5. 4
      src/core/iomgr/pollset_multipoller_with_poll_posix.c
  6. 2
      src/core/iomgr/pollset_posix.c
  7. 12
      src/core/iomgr/sockaddr_utils.c
  8. 11
      src/core/surface/call.c
  9. 23
      src/core/transport/chttp2/bin_encoder.c
  10. 3
      src/core/transport/chttp2/frame_data.c
  11. 25
      src/core/transport/chttp2/frame_goaway.c
  12. 16
      src/core/transport/chttp2/frame_rst_stream.c
  13. 22
      src/core/transport/chttp2/frame_settings.c
  14. 16
      src/core/transport/chttp2/frame_window_update.c
  15. 18
      src/core/transport/chttp2/hpack_parser.c
  16. 31
      src/core/transport/chttp2/hpack_table.c
  17. 4
      src/core/transport/chttp2/internal.h
  18. 8
      src/core/transport/chttp2/parsing.c
  19. 49
      src/core/transport/chttp2/stream_encoder.c
  20. 2
      src/core/transport/chttp2/varint.h
  21. 49
      src/core/transport/chttp2_transport.c
  22. 4
      src/core/transport/metadata.c
  23. 9
      templates/Makefile.template
  24. 2
      test/core/fling/client.c
  25. 6
      test/core/iomgr/endpoint_tests.c
  26. 3
      test/core/iomgr/fd_posix_test.c
  27. 10
      test/core/iomgr/tcp_posix_test.c
  28. 2
      test/core/iomgr/udp_server_test.c
  29. 6
      test/core/json/json_rewrite.c
  30. 3
      test/core/json/json_rewrite_test.c
  31. 6
      test/core/support/slice_test.c
  32. 8
      test/core/transport/chttp2/stream_encoder_test.c
  33. 4
      test/core/util/parse_hexstring.c
  34. 2
      test/core/util/port_posix.c
  35. 2
      test/core/util/reconnect_server.c
  36. 18
      test/core/util/test_config.h
  37. 8
      tools/codegen/core/gen_hpack_tables.c
  38. 2
      tools/codegen/core/gen_legal_metadata_characters.c

@ -231,10 +231,6 @@ endif
CXX11_CHECK_CMD = $(CXX) -std=c++11 -o $(TMPOUT) -c test/build/c++11.cc CXX11_CHECK_CMD = $(CXX) -std=c++11 -o $(TMPOUT) -c test/build/c++11.cc
HAS_CXX11 = $(shell $(CXX11_CHECK_CMD) 2> /dev/null && echo true || echo false) HAS_CXX11 = $(shell $(CXX11_CHECK_CMD) 2> /dev/null && echo true || echo false)
# Detect if -Wshorten-64-to-32 is a thing
SHORTEN_64_TO_32_CHECK_CMD = $(CC) -Wshorten-64-to-32 test/build/empty.c
HAS_SHORTEN_64_TO_32 = $(shell $(SHORTEN_64_TO_32_CHECK_CMD) 2> /dev/null && echo true || echo false)
# The HOST compiler settings are used to compile the protoc plugins. # The HOST compiler settings are used to compile the protoc plugins.
# In most cases, you won't have to change anything, but if you are # In most cases, you won't have to change anything, but if you are
# cross-compiling, you can override these variables from GNU make's # cross-compiling, you can override these variables from GNU make's
@ -249,10 +245,7 @@ ifdef EXTRA_DEFINES
DEFINES += $(EXTRA_DEFINES) DEFINES += $(EXTRA_DEFINES)
endif endif
CFLAGS += -std=c89 -pedantic -Wsign-conversion CFLAGS += -std=c89 -pedantic -Wsign-conversion -Wconversion
ifeq ($(HAS_SHORTEN_64_TO_32),true)
CFLAGS += -Wshorten-64-to-32
endif
ifeq ($(HAS_CXX11),true) ifeq ($(HAS_CXX11),true)
CXXFLAGS += -std=c++11 CXXFLAGS += -std=c++11
else else

@ -230,7 +230,10 @@ static void process_send_ops(grpc_call_element *elem,
GPR_ASSERT(calld->remaining_slice_bytes > 0); GPR_ASSERT(calld->remaining_slice_bytes > 0);
/* Increase input ref count, gpr_slice_buffer_add takes ownership. */ /* Increase input ref count, gpr_slice_buffer_add takes ownership. */
gpr_slice_buffer_add(&calld->slices, gpr_slice_ref(sop->data.slice)); gpr_slice_buffer_add(&calld->slices, gpr_slice_ref(sop->data.slice));
calld->remaining_slice_bytes -= GPR_SLICE_LENGTH(sop->data.slice); GPR_ASSERT(GPR_SLICE_LENGTH(sop->data.slice) >
calld->remaining_slice_bytes);
calld->remaining_slice_bytes -=
(gpr_uint32)GPR_SLICE_LENGTH(sop->data.slice);
if (calld->remaining_slice_bytes == 0) { if (calld->remaining_slice_bytes == 0) {
did_compress = did_compress =
compress_send_sb(calld->compression_algorithm, &calld->slices); compress_send_sb(calld->compression_algorithm, &calld->slices);

@ -218,7 +218,7 @@ static int parse_ipv4(grpc_uri *uri, struct sockaddr_storage *addr,
gpr_log(GPR_ERROR, "invalid ipv4 port: '%s'", port); gpr_log(GPR_ERROR, "invalid ipv4 port: '%s'", port);
goto done; goto done;
} }
in->sin_port = htons(port_num); in->sin_port = htons((gpr_uint16)port_num);
} else { } else {
gpr_log(GPR_ERROR, "no port given for ipv4 scheme"); gpr_log(GPR_ERROR, "no port given for ipv4 scheme");
goto done; goto done;
@ -259,7 +259,7 @@ static int parse_ipv6(grpc_uri *uri, struct sockaddr_storage *addr,
gpr_log(GPR_ERROR, "invalid ipv6 port: '%s'", port); gpr_log(GPR_ERROR, "invalid ipv6 port: '%s'", port);
goto done; goto done;
} }
in6->sin6_port = htons(port_num); in6->sin6_port = htons((gpr_uint16)port_num);
} else { } else {
gpr_log(GPR_ERROR, "no port given for ipv6 scheme"); gpr_log(GPR_ERROR, "no port given for ipv6 scheme");
goto done; goto done;

@ -123,13 +123,13 @@ static size_t shard_idx(const grpc_alarm *info) {
} }
static double ts_to_dbl(gpr_timespec ts) { static double ts_to_dbl(gpr_timespec ts) {
return ts.tv_sec + 1e-9 * ts.tv_nsec; return (double)ts.tv_sec + 1e-9 * ts.tv_nsec;
} }
static gpr_timespec dbl_to_ts(double d) { static gpr_timespec dbl_to_ts(double d) {
gpr_timespec ts; gpr_timespec ts;
ts.tv_sec = d; ts.tv_sec = (time_t)d;
ts.tv_nsec = 1e9 * (d - ts.tv_sec); ts.tv_nsec = (int)(1e9 * (d - (double)ts.tv_sec));
ts.clock_type = GPR_TIMESPAN; ts.clock_type = GPR_TIMESPAN;
return ts; return ts;
} }

@ -140,8 +140,8 @@ static void multipoll_with_poll_pollset_maybe_work(
gpr_mu_unlock(&pollset->mu); gpr_mu_unlock(&pollset->mu);
for (i = 1; i < pfd_count; i++) { for (i = 1; i < pfd_count; i++) {
pfds[i].events = grpc_fd_begin_poll(watchers[i].fd, pollset, POLLIN, pfds[i].events = (short)grpc_fd_begin_poll(watchers[i].fd, pollset, POLLIN,
POLLOUT, &watchers[i]); POLLOUT, &watchers[i]);
} }
r = grpc_poll_function(pfds, pfd_count, timeout); r = grpc_poll_function(pfds, pfd_count, timeout);

@ -443,7 +443,7 @@ static void basic_pollset_maybe_work(grpc_pollset *pollset,
pfd[1].revents = 0; pfd[1].revents = 0;
gpr_mu_unlock(&pollset->mu); gpr_mu_unlock(&pollset->mu);
pfd[1].events = pfd[1].events =
grpc_fd_begin_poll(fd, pollset, POLLIN, POLLOUT, &fd_watcher); (short)grpc_fd_begin_poll(fd, pollset, POLLIN, POLLOUT, &fd_watcher);
if (pfd[1].events != 0) { if (pfd[1].events != 0) {
nfds++; nfds++;
} }

@ -123,15 +123,17 @@ void grpc_sockaddr_make_wildcards(int port, struct sockaddr_in *wild4_out,
} }
void grpc_sockaddr_make_wildcard4(int port, struct sockaddr_in *wild_out) { void grpc_sockaddr_make_wildcard4(int port, struct sockaddr_in *wild_out) {
GPR_ASSERT(port >= 0 && port < 65536);
memset(wild_out, 0, sizeof(*wild_out)); memset(wild_out, 0, sizeof(*wild_out));
wild_out->sin_family = AF_INET; wild_out->sin_family = AF_INET;
wild_out->sin_port = htons(port); wild_out->sin_port = htons((gpr_uint16)port);
} }
void grpc_sockaddr_make_wildcard6(int port, struct sockaddr_in6 *wild_out) { void grpc_sockaddr_make_wildcard6(int port, struct sockaddr_in6 *wild_out) {
GPR_ASSERT(port >= 0 && port < 65536);
memset(wild_out, 0, sizeof(*wild_out)); memset(wild_out, 0, sizeof(*wild_out));
wild_out->sin6_family = AF_INET6; wild_out->sin6_family = AF_INET6;
wild_out->sin6_port = htons(port); wild_out->sin6_port = htons((gpr_uint16)port);
} }
int grpc_sockaddr_to_string(char **out, const struct sockaddr *addr, int grpc_sockaddr_to_string(char **out, const struct sockaddr *addr,
@ -215,10 +217,12 @@ int grpc_sockaddr_get_port(const struct sockaddr *addr) {
int grpc_sockaddr_set_port(const struct sockaddr *addr, int port) { int grpc_sockaddr_set_port(const struct sockaddr *addr, int port) {
switch (addr->sa_family) { switch (addr->sa_family) {
case AF_INET: case AF_INET:
((struct sockaddr_in *)addr)->sin_port = htons(port); GPR_ASSERT(port >= 0 && port < 65536);
((struct sockaddr_in *)addr)->sin_port = htons((gpr_uint16)port);
return 1; return 1;
case AF_INET6: case AF_INET6:
((struct sockaddr_in6 *)addr)->sin6_port = htons(port); GPR_ASSERT(port >= 0 && port < 65536);
((struct sockaddr_in6 *)addr)->sin6_port = htons((gpr_uint16)port);
return 1; return 1;
default: default:
gpr_log(GPR_ERROR, "Unknown socket family %d in grpc_sockaddr_set_port", gpr_log(GPR_ERROR, "Unknown socket family %d in grpc_sockaddr_set_port",

@ -421,7 +421,7 @@ static grpc_cq_completion *allocate_completion(grpc_call *call) {
if (call->allocated_completions & (1u << i)) { if (call->allocated_completions & (1u << i)) {
continue; continue;
} }
call->allocated_completions |= 1u << i; call->allocated_completions |= (gpr_uint8)(1u << i);
gpr_mu_unlock(&call->completion_mu); gpr_mu_unlock(&call->completion_mu);
return &call->completions[i]; return &call->completions[i];
} }
@ -432,7 +432,8 @@ static grpc_cq_completion *allocate_completion(grpc_call *call) {
static void done_completion(void *call, grpc_cq_completion *completion) { static void done_completion(void *call, grpc_cq_completion *completion) {
grpc_call *c = call; grpc_call *c = call;
gpr_mu_lock(&c->completion_mu); gpr_mu_lock(&c->completion_mu);
c->allocated_completions &= ~(1u << (completion - c->completions)); c->allocated_completions &=
(gpr_uint8) ~(1u << (completion - c->completions));
gpr_mu_unlock(&c->completion_mu); gpr_mu_unlock(&c->completion_mu);
GRPC_CALL_INTERNAL_UNREF(c, "completion", 1); GRPC_CALL_INTERNAL_UNREF(c, "completion", 1);
} }
@ -743,7 +744,7 @@ static void finish_live_ioreq_op(grpc_call *call, grpc_ioreq_op op,
size_t i; size_t i;
/* ioreq is live: we need to do something */ /* ioreq is live: we need to do something */
master = &call->masters[master_set]; master = &call->masters[master_set];
master->complete_mask |= 1u << op; master->complete_mask |= (gpr_uint16)(1u << op);
if (!success) { if (!success) {
master->success = 0; master->success = 0;
} }
@ -1214,7 +1215,7 @@ static grpc_call_error start_ioreq(grpc_call *call, const grpc_ioreq *reqs,
grpc_ioreq_completion_func completion, grpc_ioreq_completion_func completion,
void *user_data) { void *user_data) {
size_t i; size_t i;
gpr_uint32 have_ops = 0; gpr_uint16 have_ops = 0;
grpc_ioreq_op op; grpc_ioreq_op op;
reqinfo_master *master; reqinfo_master *master;
grpc_ioreq_data data; grpc_ioreq_data data;
@ -1251,7 +1252,7 @@ static grpc_call_error start_ioreq(grpc_call *call, const grpc_ioreq *reqs,
GRPC_MDSTR_REF(reqs[i].data.send_status.details)); GRPC_MDSTR_REF(reqs[i].data.send_status.details));
} }
} }
have_ops |= 1u << op; have_ops |= (gpr_uint16)(1u << op);
call->request_data[op] = data; call->request_data[op] = data;
call->request_flags[op] = reqs[i].flags; call->request_flags[op] = reqs[i].flags;

@ -128,12 +128,13 @@ gpr_slice grpc_chttp2_huffman_compress(gpr_slice input) {
while (temp_length > 8) { while (temp_length > 8) {
temp_length -= 8; temp_length -= 8;
*out++ = temp >> temp_length; *out++ = (gpr_uint8)(temp >> temp_length);
} }
} }
if (temp_length) { if (temp_length) {
*out++ = (temp << (8u - temp_length)) | (0xffu >> temp_length); *out++ = (gpr_uint8)(temp << (8u - temp_length)) |
(gpr_uint8)(0xffu >> temp_length);
} }
GPR_ASSERT(out == GPR_SLICE_END_PTR(output)); GPR_ASSERT(out == GPR_SLICE_END_PTR(output));
@ -150,7 +151,7 @@ typedef struct {
static void enc_flush_some(huff_out *out) { static void enc_flush_some(huff_out *out) {
while (out->temp_length > 8) { while (out->temp_length > 8) {
out->temp_length -= 8; out->temp_length -= 8;
*out->out++ = out->temp >> out->temp_length; *out->out++ = (gpr_uint8)(out->temp >> out->temp_length);
} }
} }
@ -189,8 +190,9 @@ gpr_slice grpc_chttp2_base64_encode_and_huffman_compress(gpr_slice input) {
/* encode full triplets */ /* encode full triplets */
for (i = 0; i < input_triplets; i++) { for (i = 0; i < input_triplets; i++) {
enc_add2(&out, in[0] >> 2, ((in[0] & 0x3) << 4) | (in[1] >> 4)); enc_add2(&out, in[0] >> 2, (gpr_uint8)((in[0] & 0x3) << 4) | (in[1] >> 4));
enc_add2(&out, ((in[1] & 0xf) << 2) | (in[2] >> 6), in[2] & 0x3f); enc_add2(&out, (gpr_uint8)((in[1] & 0xf) << 2) | (in[2] >> 6),
(gpr_uint8)(in[2] & 0x3f));
in += 3; in += 3;
} }
@ -199,19 +201,20 @@ gpr_slice grpc_chttp2_base64_encode_and_huffman_compress(gpr_slice input) {
case 0: case 0:
break; break;
case 1: case 1:
enc_add2(&out, in[0] >> 2, (in[0] & 0x3) << 4); enc_add2(&out, in[0] >> 2, (gpr_uint8)((in[0] & 0x3) << 4));
in += 1; in += 1;
break; break;
case 2: case 2:
enc_add2(&out, in[0] >> 2, ((in[0] & 0x3) << 4) | (in[1] >> 4)); enc_add2(&out, in[0] >> 2,
enc_add1(&out, (in[1] & 0xf) << 2); (gpr_uint8)((in[0] & 0x3) << 4) | (gpr_uint8)(in[1] >> 4));
enc_add1(&out, (gpr_uint8)((in[1] & 0xf) << 2));
in += 2; in += 2;
break; break;
} }
if (out.temp_length) { if (out.temp_length) {
*out.out++ = *out.out++ = (gpr_uint8)(out.temp << (8u - out.temp_length)) |
(out.temp << (8u - out.temp_length)) | (0xffu >> out.temp_length); (gpr_uint8)(0xffu >> out.temp_length);
} }
GPR_ASSERT(out.out <= GPR_SLICE_END_PTR(output)); GPR_ASSERT(out.out <= GPR_SLICE_END_PTR(output));

@ -161,7 +161,8 @@ grpc_chttp2_parse_error grpc_chttp2_data_parser_parse(
grpc_sopb_add_slice( grpc_sopb_add_slice(
&p->incoming_sopb, &p->incoming_sopb,
gpr_slice_sub(slice, (size_t)(cur - beg), (size_t)(end - beg))); gpr_slice_sub(slice, (size_t)(cur - beg), (size_t)(end - beg)));
p->frame_size -= (end - cur); GPR_ASSERT(end - cur <= p->frame_size);
p->frame_size -= (gpr_uint32)(end - cur);
return GRPC_CHTTP2_PARSE_OK; return GRPC_CHTTP2_PARSE_OK;
} }
} }

@ -137,7 +137,8 @@ grpc_chttp2_parse_error grpc_chttp2_goaway_parser_parse(
/* fallthrough */ /* fallthrough */
case GRPC_CHTTP2_GOAWAY_DEBUG: case GRPC_CHTTP2_GOAWAY_DEBUG:
memcpy(p->debug_data + p->debug_pos, cur, (size_t)(end - cur)); memcpy(p->debug_data + p->debug_pos, cur, (size_t)(end - cur));
p->debug_pos += end - cur; GPR_ASSERT(end - cur < GPR_UINT32_MAX - p->debug_pos);
p->debug_pos += (gpr_uint32)(end - cur);
p->state = GRPC_CHTTP2_GOAWAY_DEBUG; p->state = GRPC_CHTTP2_GOAWAY_DEBUG;
if (is_last) { if (is_last) {
transport_parsing->goaway_received = 1; transport_parsing->goaway_received = 1;
@ -165,9 +166,9 @@ void grpc_chttp2_goaway_append(gpr_uint32 last_stream_id, gpr_uint32 error_code,
frame_length = 4 + 4 + (gpr_uint32)GPR_SLICE_LENGTH(debug_data); frame_length = 4 + 4 + (gpr_uint32)GPR_SLICE_LENGTH(debug_data);
/* frame header: length */ /* frame header: length */
*p++ = frame_length >> 16; *p++ = (gpr_uint8)(frame_length >> 16);
*p++ = frame_length >> 8; *p++ = (gpr_uint8)(frame_length >> 8);
*p++ = frame_length; *p++ = (gpr_uint8)(frame_length);
/* frame header: type */ /* frame header: type */
*p++ = GRPC_CHTTP2_FRAME_GOAWAY; *p++ = GRPC_CHTTP2_FRAME_GOAWAY;
/* frame header: flags */ /* frame header: flags */
@ -178,15 +179,15 @@ void grpc_chttp2_goaway_append(gpr_uint32 last_stream_id, gpr_uint32 error_code,
*p++ = 0; *p++ = 0;
*p++ = 0; *p++ = 0;
/* payload: last stream id */ /* payload: last stream id */
*p++ = last_stream_id >> 24; *p++ = (gpr_uint8)(last_stream_id >> 24);
*p++ = last_stream_id >> 16; *p++ = (gpr_uint8)(last_stream_id >> 16);
*p++ = last_stream_id >> 8; *p++ = (gpr_uint8)(last_stream_id >> 8);
*p++ = last_stream_id; *p++ = (gpr_uint8)(last_stream_id);
/* payload: error code */ /* payload: error code */
*p++ = error_code >> 24; *p++ = (gpr_uint8)(error_code >> 24);
*p++ = error_code >> 16; *p++ = (gpr_uint8)(error_code >> 16);
*p++ = error_code >> 8; *p++ = (gpr_uint8)(error_code >> 8);
*p++ = error_code; *p++ = (gpr_uint8)(error_code);
GPR_ASSERT(p == GPR_SLICE_END_PTR(header)); GPR_ASSERT(p == GPR_SLICE_END_PTR(header));
gpr_slice_buffer_add(slice_buffer, header); gpr_slice_buffer_add(slice_buffer, header);
gpr_slice_buffer_add(slice_buffer, debug_data); gpr_slice_buffer_add(slice_buffer, debug_data);

@ -47,14 +47,14 @@ gpr_slice grpc_chttp2_rst_stream_create(gpr_uint32 id, gpr_uint32 code) {
*p++ = 4; *p++ = 4;
*p++ = GRPC_CHTTP2_FRAME_RST_STREAM; *p++ = GRPC_CHTTP2_FRAME_RST_STREAM;
*p++ = 0; *p++ = 0;
*p++ = id >> 24; *p++ = (gpr_uint8)(id >> 24);
*p++ = id >> 16; *p++ = (gpr_uint8)(id >> 16);
*p++ = id >> 8; *p++ = (gpr_uint8)(id >> 8);
*p++ = id; *p++ = (gpr_uint8)(id);
*p++ = code >> 24; *p++ = (gpr_uint8)(code >> 24);
*p++ = code >> 16; *p++ = (gpr_uint8)(code >> 16);
*p++ = code >> 8; *p++ = (gpr_uint8)(code >> 8);
*p++ = code; *p++ = (gpr_uint8)(code);
return slice; return slice;
} }

@ -61,9 +61,9 @@ const grpc_chttp2_setting_parameters
static gpr_uint8 *fill_header(gpr_uint8 *out, gpr_uint32 length, static gpr_uint8 *fill_header(gpr_uint8 *out, gpr_uint32 length,
gpr_uint8 flags) { gpr_uint8 flags) {
*out++ = length >> 16; *out++ = (gpr_uint8)(length >> 16);
*out++ = length >> 8; *out++ = (gpr_uint8)(length >> 8);
*out++ = length; *out++ = (gpr_uint8)(length);
*out++ = GRPC_CHTTP2_FRAME_SETTINGS; *out++ = GRPC_CHTTP2_FRAME_SETTINGS;
*out++ = flags; *out++ = flags;
*out++ = 0; *out++ = 0;
@ -90,12 +90,12 @@ gpr_slice grpc_chttp2_settings_create(gpr_uint32 *old, const gpr_uint32 *new,
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
if (new[i] != old[i] || (force_mask & (1u << i)) != 0) { if (new[i] != old[i] || (force_mask & (1u << i)) != 0) {
GPR_ASSERT(i); GPR_ASSERT(i);
*p++ = i >> 8; *p++ = (gpr_uint8)(i >> 8);
*p++ = i; *p++ = (gpr_uint8)(i);
*p++ = new[i] >> 24; *p++ = (gpr_uint8)(new[i] >> 24);
*p++ = new[i] >> 16; *p++ = (gpr_uint8)(new[i] >> 16);
*p++ = new[i] >> 8; *p++ = (gpr_uint8)(new[i] >> 8);
*p++ = new[i]; *p++ = (gpr_uint8)(new[i]);
old[i] = new[i]; old[i] = new[i];
} }
} }
@ -162,7 +162,7 @@ grpc_chttp2_parse_error grpc_chttp2_settings_parser_parse(
} }
return GRPC_CHTTP2_PARSE_OK; return GRPC_CHTTP2_PARSE_OK;
} }
parser->id = ((gpr_uint16)*cur) << 8; parser->id = (gpr_uint16)(((gpr_uint16)*cur) << 8);
cur++; cur++;
/* fallthrough */ /* fallthrough */
case GRPC_CHTTP2_SPS_ID1: case GRPC_CHTTP2_SPS_ID1:
@ -170,7 +170,7 @@ grpc_chttp2_parse_error grpc_chttp2_settings_parser_parse(
parser->state = GRPC_CHTTP2_SPS_ID1; parser->state = GRPC_CHTTP2_SPS_ID1;
return GRPC_CHTTP2_PARSE_OK; return GRPC_CHTTP2_PARSE_OK;
} }
parser->id |= (*cur); parser->id = (gpr_uint16)(parser->id | (*cur));
cur++; cur++;
/* fallthrough */ /* fallthrough */
case GRPC_CHTTP2_SPS_VAL0: case GRPC_CHTTP2_SPS_VAL0:

@ -48,14 +48,14 @@ gpr_slice grpc_chttp2_window_update_create(gpr_uint32 id,
*p++ = 4; *p++ = 4;
*p++ = GRPC_CHTTP2_FRAME_WINDOW_UPDATE; *p++ = GRPC_CHTTP2_FRAME_WINDOW_UPDATE;
*p++ = 0; *p++ = 0;
*p++ = id >> 24; *p++ = (gpr_uint8)(id >> 24);
*p++ = id >> 16; *p++ = (gpr_uint8)(id >> 16);
*p++ = id >> 8; *p++ = (gpr_uint8)(id >> 8);
*p++ = id; *p++ = (gpr_uint8)(id);
*p++ = window_update >> 24; *p++ = (gpr_uint8)(window_update >> 24);
*p++ = window_update >> 16; *p++ = (gpr_uint8)(window_update >> 16);
*p++ = window_update >> 8; *p++ = (gpr_uint8)(window_update >> 8);
*p++ = window_update; *p++ = (gpr_uint8)(window_update);
return slice; return slice;
} }

@ -1090,7 +1090,8 @@ static void append_bytes(grpc_chttp2_hpack_parser_string *str,
str->str = gpr_realloc(str->str, str->capacity); str->str = gpr_realloc(str->str, str->capacity);
} }
memcpy(str->str + str->length, data, length); memcpy(str->str + str->length, data, length);
str->length += length; GPR_ASSERT(length <= GPR_UINT32_MAX - str->length);
str->length += (gpr_uint32)length;
} }
static int append_string(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur, static int append_string(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur,
@ -1158,9 +1159,9 @@ static int append_string(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur,
goto b64_byte3; goto b64_byte3;
p->base64_buffer |= bits; p->base64_buffer |= bits;
bits = p->base64_buffer; bits = p->base64_buffer;
decoded[0] = bits >> 16; decoded[0] = (gpr_uint8)(bits >> 16);
decoded[1] = bits >> 8; decoded[1] = (gpr_uint8)(bits >> 8);
decoded[2] = bits; decoded[2] = (gpr_uint8)(bits);
append_bytes(str, decoded, 3); append_bytes(str, decoded, 3);
goto b64_byte0; goto b64_byte0;
} }
@ -1190,7 +1191,7 @@ static int finish_str(grpc_chttp2_hpack_parser *p) {
bits & 0xffff); bits & 0xffff);
return 0; return 0;
} }
decoded[0] = bits >> 16; decoded[0] = (gpr_uint8)(bits >> 16);
append_bytes(str, decoded, 1); append_bytes(str, decoded, 1);
break; break;
case B64_BYTE3: case B64_BYTE3:
@ -1200,8 +1201,8 @@ static int finish_str(grpc_chttp2_hpack_parser *p) {
bits & 0xff); bits & 0xff);
return 0; return 0;
} }
decoded[0] = bits >> 16; decoded[0] = (gpr_uint8)(bits >> 16);
decoded[1] = bits >> 8; decoded[1] = (gpr_uint8)(bits >> 8);
append_bytes(str, decoded, 2); append_bytes(str, decoded, 2);
break; break;
} }
@ -1256,7 +1257,8 @@ static int parse_string(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur,
parse_next(p, cur + remaining, end); parse_next(p, cur + remaining, end);
} else { } else {
if (!add_str_bytes(p, cur, cur + given)) return 0; if (!add_str_bytes(p, cur, cur + given)) return 0;
p->strgot += given; GPR_ASSERT(given <= GPR_UINT32_MAX - p->strgot);
p->strgot += (gpr_uint32)given;
p->state = parse_string; p->state = parse_string;
return 1; return 1;
} }

@ -150,19 +150,22 @@ grpc_mdelem *grpc_chttp2_hptbl_lookup(const grpc_chttp2_hptbl *tbl,
/* Evict one element from the table */ /* Evict one element from the table */
static void evict1(grpc_chttp2_hptbl *tbl) { static void evict1(grpc_chttp2_hptbl *tbl) {
grpc_mdelem *first_ent = tbl->ents[tbl->first_ent]; grpc_mdelem *first_ent = tbl->ents[tbl->first_ent];
tbl->mem_used -= GPR_SLICE_LENGTH(first_ent->key->slice) + size_t elem_bytes = GPR_SLICE_LENGTH(first_ent->key->slice) +
GPR_SLICE_LENGTH(first_ent->value->slice) + GPR_SLICE_LENGTH(first_ent->value->slice) +
GRPC_CHTTP2_HPACK_ENTRY_OVERHEAD; GRPC_CHTTP2_HPACK_ENTRY_OVERHEAD;
tbl->first_ent = (tbl->first_ent + 1) % GRPC_CHTTP2_MAX_TABLE_COUNT; GPR_ASSERT(elem_bytes <= tbl->mem_used);
tbl->mem_used = (gpr_uint16)(tbl->mem_used - elem_bytes);
tbl->first_ent =
(gpr_uint16)((tbl->first_ent + 1) % GRPC_CHTTP2_MAX_TABLE_COUNT);
tbl->num_ents--; tbl->num_ents--;
GRPC_MDELEM_UNREF(first_ent); GRPC_MDELEM_UNREF(first_ent);
} }
void grpc_chttp2_hptbl_add(grpc_chttp2_hptbl *tbl, grpc_mdelem *md) { void grpc_chttp2_hptbl_add(grpc_chttp2_hptbl *tbl, grpc_mdelem *md) {
/* determine how many bytes of buffer this entry represents */ /* determine how many bytes of buffer this entry represents */
gpr_uint16 elem_bytes = GPR_SLICE_LENGTH(md->key->slice) + size_t elem_bytes = GPR_SLICE_LENGTH(md->key->slice) +
GPR_SLICE_LENGTH(md->value->slice) + GPR_SLICE_LENGTH(md->value->slice) +
GRPC_CHTTP2_HPACK_ENTRY_OVERHEAD; GRPC_CHTTP2_HPACK_ENTRY_OVERHEAD;
/* we can't add elements bigger than the max table size */ /* we can't add elements bigger than the max table size */
if (elem_bytes > tbl->max_bytes) { if (elem_bytes > tbl->max_bytes) {
@ -182,7 +185,7 @@ void grpc_chttp2_hptbl_add(grpc_chttp2_hptbl *tbl, grpc_mdelem *md) {
} }
/* evict entries to ensure no overflow */ /* evict entries to ensure no overflow */
while (elem_bytes > tbl->max_bytes - tbl->mem_used) { while (elem_bytes > (size_t)tbl->max_bytes - tbl->mem_used) {
evict1(tbl); evict1(tbl);
} }
@ -190,28 +193,30 @@ void grpc_chttp2_hptbl_add(grpc_chttp2_hptbl *tbl, grpc_mdelem *md) {
tbl->ents[tbl->last_ent] = md; tbl->ents[tbl->last_ent] = md;
/* update accounting values */ /* update accounting values */
tbl->last_ent = (tbl->last_ent + 1) % GRPC_CHTTP2_MAX_TABLE_COUNT; tbl->last_ent =
(gpr_uint16)((tbl->last_ent + 1) % GRPC_CHTTP2_MAX_TABLE_COUNT);
tbl->num_ents++; tbl->num_ents++;
tbl->mem_used += elem_bytes; tbl->mem_used = (gpr_uint16)(tbl->mem_used + elem_bytes);
} }
grpc_chttp2_hptbl_find_result grpc_chttp2_hptbl_find( grpc_chttp2_hptbl_find_result grpc_chttp2_hptbl_find(
const grpc_chttp2_hptbl *tbl, grpc_mdelem *md) { const grpc_chttp2_hptbl *tbl, grpc_mdelem *md) {
grpc_chttp2_hptbl_find_result r = {0, 0}; grpc_chttp2_hptbl_find_result r = {0, 0};
int i; gpr_uint16 i;
/* See if the string is in the static table */ /* See if the string is in the static table */
for (i = 0; i < GRPC_CHTTP2_LAST_STATIC_ENTRY; i++) { for (i = 0; i < GRPC_CHTTP2_LAST_STATIC_ENTRY; i++) {
grpc_mdelem *ent = tbl->static_ents[i]; grpc_mdelem *ent = tbl->static_ents[i];
if (md->key != ent->key) continue; if (md->key != ent->key) continue;
r.index = i + 1; r.index = (gpr_uint16)(i + 1);
r.has_value = md->value == ent->value; r.has_value = md->value == ent->value;
if (r.has_value) return r; if (r.has_value) return r;
} }
/* Scan the dynamic table */ /* Scan the dynamic table */
for (i = 0; i < tbl->num_ents; i++) { for (i = 0; i < tbl->num_ents; i++) {
int idx = tbl->num_ents - i + GRPC_CHTTP2_LAST_STATIC_ENTRY; gpr_uint16 idx =
(gpr_uint16)(tbl->num_ents - i + GRPC_CHTTP2_LAST_STATIC_ENTRY);
grpc_mdelem *ent = grpc_mdelem *ent =
tbl->ents[(tbl->first_ent + i) % GRPC_CHTTP2_MAX_TABLE_COUNT]; tbl->ents[(tbl->first_ent + i) % GRPC_CHTTP2_MAX_TABLE_COUNT];
if (md->key != ent->key) continue; if (md->key != ent->key) continue;

@ -168,7 +168,7 @@ typedef struct {
grpc_iomgr_closure *pending_closures_tail; grpc_iomgr_closure *pending_closures_tail;
/** window available for us to send to peer */ /** window available for us to send to peer */
gpr_uint32 outgoing_window; gpr_int64 outgoing_window;
/** window available for peer to send to us - updated after parse */ /** window available for peer to send to us - updated after parse */
gpr_uint32 incoming_window; gpr_uint32 incoming_window;
/** how much window would we like to have for incoming_window */ /** how much window would we like to have for incoming_window */
@ -280,7 +280,7 @@ struct grpc_chttp2_transport_parsing {
gpr_uint32 goaway_last_stream_index; gpr_uint32 goaway_last_stream_index;
gpr_slice goaway_text; gpr_slice goaway_text;
gpr_uint64 outgoing_window_update; gpr_int64 outgoing_window_update;
/** pings awaiting responses */ /** pings awaiting responses */
grpc_chttp2_outstanding_ping pings; grpc_chttp2_outstanding_ping pings;

@ -411,7 +411,7 @@ int grpc_chttp2_perform_read(grpc_chttp2_transport_parsing *transport_parsing,
0)) { 0)) {
return 0; return 0;
} }
transport_parsing->incoming_frame_size -= (end - cur); transport_parsing->incoming_frame_size -= (gpr_uint32)(end - cur);
return 1; return 1;
} }
gpr_log(GPR_ERROR, "should never reach here"); gpr_log(GPR_ERROR, "should never reach here");
@ -479,7 +479,7 @@ static void skip_header(void *tp, grpc_mdelem *md) { GRPC_MDELEM_UNREF(md); }
static int init_skip_frame_parser( static int init_skip_frame_parser(
grpc_chttp2_transport_parsing *transport_parsing, int is_header) { grpc_chttp2_transport_parsing *transport_parsing, int is_header) {
if (is_header) { if (is_header) {
int is_eoh = transport_parsing->expect_continuation_stream_id != 0; gpr_uint8 is_eoh = transport_parsing->expect_continuation_stream_id != 0;
transport_parsing->parser = grpc_chttp2_header_parser_parse; transport_parsing->parser = grpc_chttp2_header_parser_parse;
transport_parsing->parser_data = &transport_parsing->hpack_parser; transport_parsing->parser_data = &transport_parsing->hpack_parser;
transport_parsing->hpack_parser.on_header = skip_header; transport_parsing->hpack_parser.on_header = skip_header;
@ -622,8 +622,8 @@ static void on_header(void *tp, grpc_mdelem *md) {
static int init_header_frame_parser( static int init_header_frame_parser(
grpc_chttp2_transport_parsing *transport_parsing, int is_continuation) { grpc_chttp2_transport_parsing *transport_parsing, int is_continuation) {
int is_eoh = (transport_parsing->incoming_frame_flags & gpr_uint8 is_eoh = (transport_parsing->incoming_frame_flags &
GRPC_CHTTP2_DATA_FLAG_END_HEADERS) != 0; GRPC_CHTTP2_DATA_FLAG_END_HEADERS) != 0;
int via_accept = 0; int via_accept = 0;
grpc_chttp2_stream_parsing *stream_parsing; grpc_chttp2_stream_parsing *stream_parsing;

@ -77,15 +77,15 @@ typedef struct {
static void fill_header(gpr_uint8 *p, gpr_uint8 type, gpr_uint32 id, size_t len, static void fill_header(gpr_uint8 *p, gpr_uint8 type, gpr_uint32 id, size_t len,
gpr_uint8 flags) { gpr_uint8 flags) {
GPR_ASSERT(len < 16777316); GPR_ASSERT(len < 16777316);
*p++ = len >> 16; *p++ = (gpr_uint8)(len >> 16);
*p++ = len >> 8; *p++ = (gpr_uint8)(len >> 8);
*p++ = len; *p++ = (gpr_uint8)(len);
*p++ = type; *p++ = type;
*p++ = flags; *p++ = flags;
*p++ = id >> 24; *p++ = (gpr_uint8)(id >> 24);
*p++ = id >> 16; *p++ = (gpr_uint8)(id >> 16);
*p++ = id >> 8; *p++ = (gpr_uint8)(id >> 8);
*p++ = id; *p++ = (gpr_uint8)(id);
} }
/* finish a frame - fill in the previously reserved header */ /* finish a frame - fill in the previously reserved header */
@ -106,11 +106,12 @@ static void finish_frame(framer_state *st, int is_header_boundary,
case NONE: case NONE:
return; return;
} }
fill_header(GPR_SLICE_START_PTR(st->output->slices[st->header_idx]), type, fill_header(
st->stream_id, GPR_SLICE_START_PTR(st->output->slices[st->header_idx]), type,
st->output->length - st->output_length_at_start_of_frame, st->stream_id, st->output->length - st->output_length_at_start_of_frame,
(is_last_in_stream ? GRPC_CHTTP2_DATA_FLAG_END_STREAM : 0) | (gpr_uint8)(
(is_header_boundary ? GRPC_CHTTP2_DATA_FLAG_END_HEADERS : 0)); (is_last_in_stream ? GRPC_CHTTP2_DATA_FLAG_END_STREAM : 0) |
(is_header_boundary ? GRPC_CHTTP2_DATA_FLAG_END_HEADERS : 0)));
st->cur_frame_type = NONE; st->cur_frame_type = NONE;
} }
@ -190,6 +191,8 @@ static grpc_mdelem *add_elem(grpc_chttp2_hpack_compressor *c,
GPR_SLICE_LENGTH(elem->value->slice); GPR_SLICE_LENGTH(elem->value->slice);
grpc_mdelem *elem_to_unref; grpc_mdelem *elem_to_unref;
GPR_ASSERT(elem_size < 65536);
/* Reserve space for this element in the remote table: if this overflows /* Reserve space for this element in the remote table: if this overflows
the current table, drop elements until it fits, matching the decompressor the current table, drop elements until it fits, matching the decompressor
algorithm */ algorithm */
@ -201,14 +204,16 @@ static grpc_mdelem *add_elem(grpc_chttp2_hpack_compressor *c,
c->table_elem_size[c->tail_remote_index % c->table_elem_size[c->tail_remote_index %
GRPC_CHTTP2_HPACKC_MAX_TABLE_ELEMS]); GRPC_CHTTP2_HPACKC_MAX_TABLE_ELEMS]);
GPR_ASSERT(c->table_elems > 0); GPR_ASSERT(c->table_elems > 0);
c->table_size -= c->table_elem_size[c->tail_remote_index % c->table_size =
GRPC_CHTTP2_HPACKC_MAX_TABLE_ELEMS]; (gpr_uint16)(c->table_size -
c->table_elem_size[c->tail_remote_index %
GRPC_CHTTP2_HPACKC_MAX_TABLE_ELEMS]);
c->table_elems--; c->table_elems--;
} }
GPR_ASSERT(c->table_elems < GRPC_CHTTP2_HPACKC_MAX_TABLE_ELEMS); GPR_ASSERT(c->table_elems < GRPC_CHTTP2_HPACKC_MAX_TABLE_ELEMS);
c->table_elem_size[new_index % GRPC_CHTTP2_HPACKC_MAX_TABLE_ELEMS] = c->table_elem_size[new_index % GRPC_CHTTP2_HPACKC_MAX_TABLE_ELEMS] =
elem_size; (gpr_uint16)elem_size;
c->table_size += elem_size; c->table_size = (gpr_uint16)(c->table_size + elem_size);
c->table_elems++; c->table_elems++;
/* Store this element into {entries,indices}_elem */ /* Store this element into {entries,indices}_elem */
@ -497,7 +502,7 @@ gpr_uint32 grpc_chttp2_preencode(grpc_stream_op *inops, size_t *inops_count,
gpr_uint32 flow_controlled_bytes_taken = 0; gpr_uint32 flow_controlled_bytes_taken = 0;
gpr_uint32 curop = 0; gpr_uint32 curop = 0;
gpr_uint8 *p; gpr_uint8 *p;
int compressed_flag_set = 0; gpr_uint8 compressed_flag_set = 0;
while (curop < *inops_count) { while (curop < *inops_count) {
GPR_ASSERT(flow_controlled_bytes_taken <= max_flow_controlled_bytes); GPR_ASSERT(flow_controlled_bytes_taken <= max_flow_controlled_bytes);
@ -523,10 +528,10 @@ gpr_uint32 grpc_chttp2_preencode(grpc_stream_op *inops, size_t *inops_count,
p = GPR_SLICE_START_PTR(slice); p = GPR_SLICE_START_PTR(slice);
p[0] = compressed_flag_set; p[0] = compressed_flag_set;
p[1] = op->data.begin_message.length >> 24; p[1] = (gpr_uint8)(op->data.begin_message.length >> 24);
p[2] = op->data.begin_message.length >> 16; p[2] = (gpr_uint8)(op->data.begin_message.length >> 16);
p[3] = op->data.begin_message.length >> 8; p[3] = (gpr_uint8)(op->data.begin_message.length >> 8);
p[4] = op->data.begin_message.length; p[4] = (gpr_uint8)(op->data.begin_message.length);
op->type = GRPC_OP_SLICE; op->type = GRPC_OP_SLICE;
op->data.slice = slice; op->data.slice = slice;
/* fallthrough */ /* fallthrough */
@ -550,7 +555,7 @@ gpr_uint32 grpc_chttp2_preencode(grpc_stream_op *inops, size_t *inops_count,
grpc_sopb_append(outops, op, 1); grpc_sopb_append(outops, op, 1);
curop++; curop++;
} }
flow_controlled_bytes_taken += GPR_SLICE_LENGTH(slice); flow_controlled_bytes_taken += (gpr_uint32)GPR_SLICE_LENGTH(slice);
break; break;
} }
} }

@ -63,7 +63,7 @@ void grpc_chttp2_hpack_write_varint_tail(gpr_uint32 tail_value,
do { \ do { \
gpr_uint8* tgt = target; \ gpr_uint8* tgt = target; \
if ((length) == 1u) { \ if ((length) == 1u) { \
(tgt)[0] = (prefix_or) | (n); \ (tgt)[0] = (gpr_uint8)((prefix_or) | (n)); \
} else { \ } else { \
(tgt)[0] = (prefix_or) | GRPC_CHTTP2_MAX_IN_PREFIX(prefix_bits); \ (tgt)[0] = (prefix_or) | GRPC_CHTTP2_MAX_IN_PREFIX(prefix_bits); \
grpc_chttp2_hpack_write_varint_tail( \ grpc_chttp2_hpack_write_varint_tail( \

@ -209,7 +209,7 @@ static void ref_transport(grpc_chttp2_transport *t) { gpr_ref(&t->refs); }
static void init_transport(grpc_chttp2_transport *t, static void init_transport(grpc_chttp2_transport *t,
const grpc_channel_args *channel_args, const grpc_channel_args *channel_args,
grpc_endpoint *ep, grpc_mdctx *mdctx, grpc_endpoint *ep, grpc_mdctx *mdctx,
int is_client) { gpr_uint8 is_client) {
size_t i; size_t i;
int j; int j;
@ -683,6 +683,8 @@ static void perform_stream_op_locked(
stream_global->publish_sopb = op->recv_ops; stream_global->publish_sopb = op->recv_ops;
stream_global->publish_sopb->nops = 0; stream_global->publish_sopb->nops = 0;
stream_global->publish_state = op->recv_state; stream_global->publish_state = op->recv_state;
/* clamp max recv bytes */
op->max_recv_bytes = GPR_MIN(op->max_recv_bytes, GPR_UINT32_MAX);
if (stream_global->max_recv_bytes < op->max_recv_bytes) { if (stream_global->max_recv_bytes < op->max_recv_bytes) {
GRPC_CHTTP2_FLOWCTL_TRACE_STREAM( GRPC_CHTTP2_FLOWCTL_TRACE_STREAM(
"op", transport_global, stream_global, max_recv_bytes, "op", transport_global, stream_global, max_recv_bytes,
@ -691,9 +693,8 @@ static void perform_stream_op_locked(
"op", transport_global, stream_global, unannounced_incoming_window, "op", transport_global, stream_global, unannounced_incoming_window,
op->max_recv_bytes - stream_global->max_recv_bytes); op->max_recv_bytes - stream_global->max_recv_bytes);
stream_global->unannounced_incoming_window += stream_global->unannounced_incoming_window +=
op->max_recv_bytes - stream_global->max_recv_bytes; (gpr_uint32)op->max_recv_bytes - stream_global->max_recv_bytes;
stream_global->max_recv_bytes = stream_global->max_recv_bytes = (gpr_uint32)op->max_recv_bytes;
(gpr_uint32)(GPR_MIN(op->max_recv_bytes, GPR_UINT32_MAX));
} }
grpc_chttp2_incoming_metadata_live_op_buffer_end( grpc_chttp2_incoming_metadata_live_op_buffer_end(
&stream_global->outstanding_metadata); &stream_global->outstanding_metadata);
@ -730,14 +731,14 @@ static void send_ping_locked(grpc_chttp2_transport *t,
p->next = &t->global.pings; p->next = &t->global.pings;
p->prev = p->next->prev; p->prev = p->next->prev;
p->prev->next = p->next->prev = p; p->prev->next = p->next->prev = p;
p->id[0] = (t->global.ping_counter >> 56) & 0xff; p->id[0] = (gpr_uint8)((t->global.ping_counter >> 56) & 0xff);
p->id[1] = (t->global.ping_counter >> 48) & 0xff; p->id[1] = (gpr_uint8)((t->global.ping_counter >> 48) & 0xff);
p->id[2] = (t->global.ping_counter >> 40) & 0xff; p->id[2] = (gpr_uint8)((t->global.ping_counter >> 40) & 0xff);
p->id[3] = (t->global.ping_counter >> 32) & 0xff; p->id[3] = (gpr_uint8)((t->global.ping_counter >> 32) & 0xff);
p->id[4] = (t->global.ping_counter >> 24) & 0xff; p->id[4] = (gpr_uint8)((t->global.ping_counter >> 24) & 0xff);
p->id[5] = (t->global.ping_counter >> 16) & 0xff; p->id[5] = (gpr_uint8)((t->global.ping_counter >> 16) & 0xff);
p->id[6] = (t->global.ping_counter >> 8) & 0xff; p->id[6] = (gpr_uint8)((t->global.ping_counter >> 8) & 0xff);
p->id[7] = t->global.ping_counter & 0xff; p->id[7] = (gpr_uint8)(t->global.ping_counter & 0xff);
p->on_recv = on_recv; p->on_recv = on_recv;
gpr_slice_buffer_add(&t->global.qbuf, grpc_chttp2_ping_create(0, p->id)); gpr_slice_buffer_add(&t->global.qbuf, grpc_chttp2_ping_create(0, p->id));
} }
@ -999,7 +1000,7 @@ static void close_from_api(grpc_chttp2_transport_global *transport_global,
*p++ = (gpr_uint8)('0' + (status % 10)); *p++ = (gpr_uint8)('0' + (status % 10));
} }
GPR_ASSERT(p == GPR_SLICE_END_PTR(status_hdr)); GPR_ASSERT(p == GPR_SLICE_END_PTR(status_hdr));
len += GPR_SLICE_LENGTH(status_hdr); len += (gpr_uint32)GPR_SLICE_LENGTH(status_hdr);
if (optional_message) { if (optional_message) {
GPR_ASSERT(GPR_SLICE_LENGTH(*optional_message) < 127); GPR_ASSERT(GPR_SLICE_LENGTH(*optional_message) < 127);
@ -1019,23 +1020,23 @@ static void close_from_api(grpc_chttp2_transport_global *transport_global,
*p++ = 'a'; *p++ = 'a';
*p++ = 'g'; *p++ = 'g';
*p++ = 'e'; *p++ = 'e';
*p++ = GPR_SLICE_LENGTH(*optional_message); *p++ = (gpr_uint8)GPR_SLICE_LENGTH(*optional_message);
GPR_ASSERT(p == GPR_SLICE_END_PTR(message_pfx)); GPR_ASSERT(p == GPR_SLICE_END_PTR(message_pfx));
len += GPR_SLICE_LENGTH(message_pfx); len += (gpr_uint32)GPR_SLICE_LENGTH(message_pfx);
len += GPR_SLICE_LENGTH(*optional_message); len += (gpr_uint32)GPR_SLICE_LENGTH(*optional_message);
} }
hdr = gpr_slice_malloc(9); hdr = gpr_slice_malloc(9);
p = GPR_SLICE_START_PTR(hdr); p = GPR_SLICE_START_PTR(hdr);
*p++ = len >> 16; *p++ = (gpr_uint8)(len >> 16);
*p++ = len >> 8; *p++ = (gpr_uint8)(len >> 8);
*p++ = len; *p++ = (gpr_uint8)(len);
*p++ = GRPC_CHTTP2_FRAME_HEADER; *p++ = GRPC_CHTTP2_FRAME_HEADER;
*p++ = GRPC_CHTTP2_DATA_FLAG_END_STREAM | GRPC_CHTTP2_DATA_FLAG_END_HEADERS; *p++ = GRPC_CHTTP2_DATA_FLAG_END_STREAM | GRPC_CHTTP2_DATA_FLAG_END_HEADERS;
*p++ = stream_global->id >> 24; *p++ = (gpr_uint8)(stream_global->id >> 24);
*p++ = stream_global->id >> 16; *p++ = (gpr_uint8)(stream_global->id >> 16);
*p++ = stream_global->id >> 8; *p++ = (gpr_uint8)(stream_global->id >> 8);
*p++ = stream_global->id; *p++ = (gpr_uint8)(stream_global->id);
GPR_ASSERT(p == GPR_SLICE_END_PTR(hdr)); GPR_ASSERT(p == GPR_SLICE_END_PTR(hdr));
gpr_slice_buffer_add(&transport_global->qbuf, hdr); gpr_slice_buffer_add(&transport_global->qbuf, hdr);
@ -1281,7 +1282,7 @@ grpc_transport *grpc_create_chttp2_transport(
const grpc_channel_args *channel_args, grpc_endpoint *ep, grpc_mdctx *mdctx, const grpc_channel_args *channel_args, grpc_endpoint *ep, grpc_mdctx *mdctx,
int is_client) { int is_client) {
grpc_chttp2_transport *t = gpr_malloc(sizeof(grpc_chttp2_transport)); grpc_chttp2_transport *t = gpr_malloc(sizeof(grpc_chttp2_transport));
init_transport(t, channel_args, ep, mdctx, is_client); init_transport(t, channel_args, ep, mdctx, is_client != 0);
return &t->base; return &t->base;
} }

@ -334,7 +334,7 @@ grpc_mdstr *grpc_mdstr_from_string(grpc_mdctx *ctx, const char *str,
grpc_mdstr *ret; grpc_mdstr *ret;
for (i = 0; i < len; i++) { for (i = 0; i < len; i++) {
if (str[i] >= 'A' && str[i] <= 'Z') { if (str[i] >= 'A' && str[i] <= 'Z') {
copy[i] = str[i] - 'A' + 'a'; copy[i] = (char)(str[i] - 'A' + 'a');
} else { } else {
copy[i] = str[i]; copy[i] = str[i];
} }
@ -379,7 +379,7 @@ grpc_mdstr *grpc_mdstr_from_buffer(grpc_mdctx *ctx, const gpr_uint8 *buf,
s->slice.refcount = NULL; s->slice.refcount = NULL;
memcpy(s->slice.data.inlined.bytes, buf, length); memcpy(s->slice.data.inlined.bytes, buf, length);
s->slice.data.inlined.bytes[length] = 0; s->slice.data.inlined.bytes[length] = 0;
s->slice.data.inlined.length = length; s->slice.data.inlined.length = (gpr_uint8)length;
} else { } else {
/* string data goes after the internal_string header, and we +1 for null /* string data goes after the internal_string header, and we +1 for null
terminator */ terminator */

@ -247,10 +247,6 @@
CXX11_CHECK_CMD = $(CXX) -std=c++11 -o $(TMPOUT) -c test/build/c++11.cc CXX11_CHECK_CMD = $(CXX) -std=c++11 -o $(TMPOUT) -c test/build/c++11.cc
HAS_CXX11 = $(shell $(CXX11_CHECK_CMD) 2> /dev/null && echo true || echo false) HAS_CXX11 = $(shell $(CXX11_CHECK_CMD) 2> /dev/null && echo true || echo false)
# Detect if -Wshorten-64-to-32 is a thing
SHORTEN_64_TO_32_CHECK_CMD = $(CC) -Wshorten-64-to-32 test/build/empty.c
HAS_SHORTEN_64_TO_32 = $(shell $(SHORTEN_64_TO_32_CHECK_CMD) 2> /dev/null && echo true || echo false)
# The HOST compiler settings are used to compile the protoc plugins. # The HOST compiler settings are used to compile the protoc plugins.
# In most cases, you won't have to change anything, but if you are # In most cases, you won't have to change anything, but if you are
# cross-compiling, you can override these variables from GNU make's # cross-compiling, you can override these variables from GNU make's
@ -265,10 +261,7 @@
DEFINES += $(EXTRA_DEFINES) DEFINES += $(EXTRA_DEFINES)
endif endif
CFLAGS += -std=c89 -pedantic -Wsign-conversion CFLAGS += -std=c89 -pedantic -Wsign-conversion -Wconversion
ifeq ($(HAS_SHORTEN_64_TO_32),true)
CFLAGS += -Wshorten-64-to-32
endif
ifeq ($(HAS_CXX11),true) ifeq ($(HAS_CXX11),true)
CXXFLAGS += -std=c++11 CXXFLAGS += -std=c++11
else else

@ -130,7 +130,7 @@ static void step_ping_pong_stream(void) {
static double now(void) { static double now(void) {
gpr_timespec tv = gpr_now(GPR_CLOCK_REALTIME); gpr_timespec tv = gpr_now(GPR_CLOCK_REALTIME);
return 1e9 * tv.tv_sec + tv.tv_nsec; return 1e9 * (double)tv.tv_sec + tv.tv_nsec;
} }
typedef struct { typedef struct {

@ -86,7 +86,7 @@ static grpc_endpoint_test_fixture begin_test(grpc_endpoint_test_config config,
static void end_test(grpc_endpoint_test_config config) { config.clean_up(); } static void end_test(grpc_endpoint_test_config config) { config.clean_up(); }
static gpr_slice *allocate_blocks(size_t num_bytes, size_t slice_size, static gpr_slice *allocate_blocks(size_t num_bytes, size_t slice_size,
size_t *num_blocks, int *current_data) { size_t *num_blocks, gpr_uint8 *current_data) {
size_t nslices = num_bytes / slice_size + (num_bytes % slice_size ? 1 : 0); size_t nslices = num_bytes / slice_size + (num_bytes % slice_size ? 1 : 0);
gpr_slice *slices = malloc(sizeof(gpr_slice) * nslices); gpr_slice *slices = malloc(sizeof(gpr_slice) * nslices);
size_t num_bytes_left = num_bytes; size_t num_bytes_left = num_bytes;
@ -102,7 +102,7 @@ static gpr_slice *allocate_blocks(size_t num_bytes, size_t slice_size,
buf = GPR_SLICE_START_PTR(slices[i]); buf = GPR_SLICE_START_PTR(slices[i]);
for (j = 0; j < GPR_SLICE_LENGTH(slices[i]); ++j) { for (j = 0; j < GPR_SLICE_LENGTH(slices[i]); ++j) {
buf[j] = *current_data; buf[j] = *current_data;
*current_data = (*current_data + 1) % 256; (*current_data)++;
} }
} }
GPR_ASSERT(num_bytes_left == 0); GPR_ASSERT(num_bytes_left == 0);
@ -117,7 +117,7 @@ struct read_and_write_test_state {
size_t current_write_size; size_t current_write_size;
size_t bytes_written; size_t bytes_written;
int current_read_data; int current_read_data;
int current_write_data; gpr_uint8 current_write_data;
int read_done; int read_done;
int write_done; int write_done;
gpr_slice_buffer incoming; gpr_slice_buffer incoming;

@ -83,7 +83,8 @@ static void create_test_socket(int port, int *socket_fd,
/* Use local address for test */ /* Use local address for test */
sin->sin_family = AF_INET; sin->sin_family = AF_INET;
sin->sin_addr.s_addr = htonl(0x7f000001); sin->sin_addr.s_addr = htonl(0x7f000001);
sin->sin_port = htons(port); GPR_ASSERT(port >= 0 && port < 65536);
sin->sin_port = htons((gpr_uint16)port);
} }
/* Dummy gRPC callback */ /* Dummy gRPC callback */

@ -81,7 +81,7 @@ static ssize_t fill_socket(int fd) {
int i; int i;
unsigned char buf[256]; unsigned char buf[256];
for (i = 0; i < 256; ++i) { for (i = 0; i < 256; ++i) {
buf[i] = i; buf[i] = (gpr_uint8)i;
} }
do { do {
write_bytes = write(fd, buf, 256); write_bytes = write(fd, buf, 256);
@ -99,7 +99,7 @@ static size_t fill_socket_partial(int fd, size_t bytes) {
unsigned char *buf = malloc(bytes); unsigned char *buf = malloc(bytes);
unsigned i; unsigned i;
for (i = 0; i < bytes; ++i) { for (i = 0; i < bytes; ++i) {
buf[i] = i % 256; buf[i] = (gpr_uint8)(i % 256);
} }
do { do {
@ -276,7 +276,7 @@ struct write_socket_state {
}; };
static gpr_slice *allocate_blocks(size_t num_bytes, size_t slice_size, static gpr_slice *allocate_blocks(size_t num_bytes, size_t slice_size,
size_t *num_blocks, int *current_data) { size_t *num_blocks, gpr_uint8 *current_data) {
size_t nslices = num_bytes / slice_size + (num_bytes % slice_size ? 1u : 0u); size_t nslices = num_bytes / slice_size + (num_bytes % slice_size ? 1u : 0u);
gpr_slice *slices = gpr_malloc(sizeof(gpr_slice) * nslices); gpr_slice *slices = gpr_malloc(sizeof(gpr_slice) * nslices);
size_t num_bytes_left = num_bytes; size_t num_bytes_left = num_bytes;
@ -291,7 +291,7 @@ static gpr_slice *allocate_blocks(size_t num_bytes, size_t slice_size,
buf = GPR_SLICE_START_PTR(slices[i]); buf = GPR_SLICE_START_PTR(slices[i]);
for (j = 0; j < GPR_SLICE_LENGTH(slices[i]); ++j) { for (j = 0; j < GPR_SLICE_LENGTH(slices[i]); ++j) {
buf[j] = *current_data; buf[j] = *current_data;
*current_data = (*current_data + 1) % 256; (*current_data)++;
} }
} }
GPR_ASSERT(num_bytes_left == 0); GPR_ASSERT(num_bytes_left == 0);
@ -373,7 +373,7 @@ static void write_test(size_t num_bytes, size_t slice_size) {
ssize_t read_bytes; ssize_t read_bytes;
size_t num_blocks; size_t num_blocks;
gpr_slice *slices; gpr_slice *slices;
int current_data = 0; gpr_uint8 current_data = 0;
gpr_slice_buffer outgoing; gpr_slice_buffer outgoing;
grpc_iomgr_closure write_done_closure; grpc_iomgr_closure write_done_closure;
gpr_timespec deadline = GRPC_TIMEOUT_SECONDS_TO_DEADLINE(20); gpr_timespec deadline = GRPC_TIMEOUT_SECONDS_TO_DEADLINE(20);

@ -59,7 +59,7 @@ static void on_read(int fd, grpc_udp_server_cb new_transport_cb, void *cb_arg) {
byte_count = recv(fd, read_buffer, sizeof(read_buffer), 0); byte_count = recv(fd, read_buffer, sizeof(read_buffer), 0);
g_number_of_reads++; g_number_of_reads++;
g_number_of_bytes_read += byte_count; g_number_of_bytes_read += (int)byte_count;
grpc_pollset_kick(&g_pollset, NULL); grpc_pollset_kick(&g_pollset, NULL);
gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset)); gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset));

@ -34,8 +34,9 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <grpc/support/cmdline.h>
#include <grpc/support/alloc.h> #include <grpc/support/alloc.h>
#include <grpc/support/cmdline.h>
#include <grpc/support/log.h>
#include "src/core/json/json_reader.h" #include "src/core/json/json_reader.h"
#include "src/core/json/json_writer.h" #include "src/core/json/json_writer.h"
@ -96,7 +97,8 @@ static void json_reader_string_clear(void* userdata) {
static void json_reader_string_add_char(void* userdata, gpr_uint32 c) { static void json_reader_string_add_char(void* userdata, gpr_uint32 c) {
json_reader_userdata* state = userdata; json_reader_userdata* state = userdata;
check_string(state, 1); check_string(state, 1);
state->scratchpad[state->string_len++] = c; GPR_ASSERT(c < 256);
state->scratchpad[state->string_len++] = (char)c;
} }
static void json_reader_string_add_utf32(void* userdata, gpr_uint32 c) { static void json_reader_string_add_utf32(void* userdata, gpr_uint32 c) {

@ -108,7 +108,8 @@ static void json_reader_string_clear(void* userdata) {
static void json_reader_string_add_char(void* userdata, gpr_uint32 c) { static void json_reader_string_add_char(void* userdata, gpr_uint32 c) {
json_reader_userdata* state = userdata; json_reader_userdata* state = userdata;
check_string(state, 1); check_string(state, 1);
state->scratchpad[state->string_len++] = c; GPR_ASSERT(c <= 256);
state->scratchpad[state->string_len++] = (char)c;
} }
static void json_reader_string_add_utf32(void* userdata, gpr_uint32 c) { static void json_reader_string_add_utf32(void* userdata, gpr_uint32 c) {

@ -116,7 +116,7 @@ static void test_slice_sub_works(unsigned length) {
beginning of the slice. */ beginning of the slice. */
slice = gpr_slice_malloc(length); slice = gpr_slice_malloc(length);
for (i = 0; i < length; i++) { for (i = 0; i < length; i++) {
GPR_SLICE_START_PTR(slice)[i] = i; GPR_SLICE_START_PTR(slice)[i] = (gpr_uint8)i;
} }
/* Ensure that for all subsets length is correct and that we start on the /* Ensure that for all subsets length is correct and that we start on the
@ -155,7 +155,7 @@ static void test_slice_split_head_works(size_t length) {
beginning of the slice. */ beginning of the slice. */
slice = gpr_slice_malloc(length); slice = gpr_slice_malloc(length);
for (i = 0; i < length; i++) { for (i = 0; i < length; i++) {
GPR_SLICE_START_PTR(slice)[i] = i; GPR_SLICE_START_PTR(slice)[i] = (gpr_uint8)i;
} }
/* Ensure that for all subsets length is correct and that we start on the /* Ensure that for all subsets length is correct and that we start on the
@ -183,7 +183,7 @@ static void test_slice_split_tail_works(size_t length) {
beginning of the slice. */ beginning of the slice. */
slice = gpr_slice_malloc(length); slice = gpr_slice_malloc(length);
for (i = 0; i < length; i++) { for (i = 0; i < length; i++) {
GPR_SLICE_START_PTR(slice)[i] = i; GPR_SLICE_START_PTR(slice)[i] = (gpr_uint8)i;
} }
/* Ensure that for all subsets length is correct and that we start on the /* Ensure that for all subsets length is correct and that we start on the

@ -59,7 +59,7 @@ static gpr_slice create_test_slice(size_t length) {
gpr_slice slice = gpr_slice_malloc(length); gpr_slice slice = gpr_slice_malloc(length);
size_t i; size_t i;
for (i = 0; i < length; i++) { for (i = 0; i < length; i++) {
GPR_SLICE_START_PTR(slice)[i] = i; GPR_SLICE_START_PTR(slice)[i] = (gpr_uint8)i;
} }
return slice; return slice;
} }
@ -196,10 +196,10 @@ static void test_basic_headers(void) {
} }
static void encode_int_to_str(int i, char *p) { static void encode_int_to_str(int i, char *p) {
p[0] = 'a' + i % 26; p[0] = (char)('a' + i % 26);
i /= 26; i /= 26;
GPR_ASSERT(i < 26); GPR_ASSERT(i < 26);
p[1] = 'a' + i; p[1] = (char)('a' + i);
p[2] = 0; p[2] = 0;
} }
@ -246,7 +246,7 @@ static void randstr(char *p, int bufsz) {
int i; int i;
int len = 1 + rand() % bufsz; int len = 1 + rand() % bufsz;
for (i = 0; i < len; i++) { for (i = 0; i < len; i++) {
p[i] = 'a' + rand() % 26; p[i] = (char)('a' + rand() % 26);
} }
p[len] = 0; p[len] = 0;
} }

@ -54,10 +54,10 @@ gpr_slice parse_hexstring(const char *hexstring) {
temp = 0; temp = 0;
for (p = hexstring; *p; p++) { for (p = hexstring; *p; p++) {
if (*p >= '0' && *p <= '9') { if (*p >= '0' && *p <= '9') {
temp = (temp << 4) | (*p - '0'); temp = (gpr_uint8)(temp << 4) | (gpr_uint8)(*p - '0');
nibbles++; nibbles++;
} else if (*p >= 'a' && *p <= 'f') { } else if (*p >= 'a' && *p <= 'f') {
temp = (temp << 4) | (*p - 'a' + 10); temp = (gpr_uint8)(temp << 4) | (gpr_uint8)(*p - 'a' + 10);
nibbles++; nibbles++;
} }
if (nibbles == 2) { if (nibbles == 2) {

@ -102,7 +102,7 @@ static int is_port_available(int *port, int is_tcp) {
/* Try binding to port */ /* Try binding to port */
addr.sin_family = AF_INET; addr.sin_family = AF_INET;
addr.sin_addr.s_addr = INADDR_ANY; addr.sin_addr.s_addr = INADDR_ANY;
addr.sin_port = htons(*port); addr.sin_port = htons((gpr_uint16)*port);
if (bind(fd, (struct sockaddr *)&addr, sizeof(addr)) < 0) { if (bind(fd, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
gpr_log(GPR_DEBUG, "bind(port=%d) failed: %s", *port, strerror(errno)); gpr_log(GPR_DEBUG, "bind(port=%d) failed: %s", *port, strerror(errno));
close(fd); close(fd);

@ -116,7 +116,7 @@ void reconnect_server_start(reconnect_server *server, int port) {
int port_added; int port_added;
addr.sin_family = AF_INET; addr.sin_family = AF_INET;
addr.sin_port = htons(port); addr.sin_port = htons((gpr_uint16)port);
memset(&addr.sin_addr, 0, sizeof(addr.sin_addr)); memset(&addr.sin_addr, 0, sizeof(addr.sin_addr));
server->tcp_server = grpc_tcp_server_create(); server->tcp_server = grpc_tcp_server_create();

@ -54,15 +54,17 @@ extern double g_fixture_slowdown_factor;
(GRPC_TEST_SLOWDOWN_BUILD_FACTOR * GRPC_TEST_SLOWDOWN_MACHINE_FACTOR * \ (GRPC_TEST_SLOWDOWN_BUILD_FACTOR * GRPC_TEST_SLOWDOWN_MACHINE_FACTOR * \
g_fixture_slowdown_factor) g_fixture_slowdown_factor)
#define GRPC_TIMEOUT_SECONDS_TO_DEADLINE(x) \ #define GRPC_TIMEOUT_SECONDS_TO_DEADLINE(x) \
gpr_time_add(gpr_now(GPR_CLOCK_MONOTONIC), \ gpr_time_add( \
gpr_time_from_millis(GRPC_TEST_SLOWDOWN_FACTOR * 1e3 * (x), \ gpr_now(GPR_CLOCK_MONOTONIC), \
GPR_TIMESPAN)) gpr_time_from_millis((long)(GRPC_TEST_SLOWDOWN_FACTOR * 1e3 * (x)), \
GPR_TIMESPAN))
#define GRPC_TIMEOUT_MILLIS_TO_DEADLINE(x) \ #define GRPC_TIMEOUT_MILLIS_TO_DEADLINE(x) \
gpr_time_add(gpr_now(GPR_CLOCK_MONOTONIC), \ gpr_time_add( \
gpr_time_from_micros(GRPC_TEST_SLOWDOWN_FACTOR * 1e3 * (x), \ gpr_now(GPR_CLOCK_MONOTONIC), \
GPR_TIMESPAN)) gpr_time_from_micros((long)(GRPC_TEST_SLOWDOWN_FACTOR * 1e3 * (x)), \
GPR_TIMESPAN))
#ifndef GRPC_TEST_CUSTOM_PICK_PORT #ifndef GRPC_TEST_CUSTOM_PICK_PORT
#define GRPC_TEST_PICK_PORT #define GRPC_TEST_PICK_PORT

@ -71,13 +71,13 @@ static unsigned char prefix_mask(unsigned char prefix_len) {
unsigned char i; unsigned char i;
unsigned char out = 0; unsigned char out = 0;
for (i = 0; i < prefix_len; i++) { for (i = 0; i < prefix_len; i++) {
out |= 1 << (7 - i); out |= (unsigned char)(1 << (7 - i));
} }
return out; return out;
} }
static unsigned char suffix_mask(unsigned char prefix_len) { static unsigned char suffix_mask(unsigned char prefix_len) {
return ~prefix_mask(prefix_len); return (unsigned char)~prefix_mask(prefix_len);
} }
static void generate_first_byte_lut(void) { static void generate_first_byte_lut(void) {
@ -92,7 +92,7 @@ static void generate_first_byte_lut(void) {
chrspec = NULL; chrspec = NULL;
for (j = 0; j < num_fields; j++) { for (j = 0; j < num_fields; j++) {
if ((prefix_mask(fields[j].prefix_length) & i) == fields[j].prefix) { if ((prefix_mask(fields[j].prefix_length) & i) == fields[j].prefix) {
suffix = suffix_mask(fields[j].prefix_length) & i; suffix = suffix_mask(fields[j].prefix_length) & (unsigned char)i;
if (suffix == suffix_mask(fields[j].prefix_length)) { if (suffix == suffix_mask(fields[j].prefix_length)) {
if (fields[j].index != 2) continue; if (fields[j].index != 2) continue;
} else if (suffix == 0) { } else if (suffix == 0) {
@ -336,7 +336,7 @@ static void generate_base64_inverse_table(void) {
memset(inverse, 255, sizeof(inverse)); memset(inverse, 255, sizeof(inverse));
for (i = 0; i < strlen(alphabet); i++) { for (i = 0; i < strlen(alphabet); i++) {
inverse[(unsigned char)alphabet[i]] = i; inverse[(unsigned char)alphabet[i]] = (unsigned char)i;
} }
printf("static const gpr_uint8 inverse_base64[256] = {"); printf("static const gpr_uint8 inverse_base64[256] = {");

@ -41,7 +41,7 @@ static unsigned char legal_bits[256 / 8];
static void legal(int x) { static void legal(int x) {
int byte = x / 8; int byte = x / 8;
int bit = x % 8; int bit = x % 8;
legal_bits[byte] |= 1 << bit; legal_bits[byte] |= (unsigned char)(1 << bit);
} }
static void dump(void) { static void dump(void) {

Loading…
Cancel
Save