From 32ca48ce0b963949ff29d2dcd526b174679779aa Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Thu, 10 Sep 2015 11:47:15 -0700 Subject: Core compiles with -Wsign-conversion --- src/core/transport/chttp2/parsing.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'src/core/transport/chttp2/parsing.c') diff --git a/src/core/transport/chttp2/parsing.c b/src/core/transport/chttp2/parsing.c index dc5eb18e42..b0f884e258 100644 --- a/src/core/transport/chttp2/parsing.c +++ b/src/core/transport/chttp2/parsing.c @@ -194,7 +194,8 @@ void grpc_chttp2_publish_reads( GRPC_CHTTP2_FLOWCTL_TRACE_STREAM( "parsed", transport_parsing, stream_parsing, outgoing_window_update, -(gpr_int64)stream_parsing->outgoing_window_update); - stream_global->outgoing_window += stream_parsing->outgoing_window_update; + stream_global->outgoing_window += + (gpr_uint32)stream_global->outgoing_window; stream_parsing->outgoing_window_update = 0; is_zero = stream_global->outgoing_window <= 0; if (was_zero && !is_zero) { @@ -379,9 +380,10 @@ int grpc_chttp2_perform_read(grpc_chttp2_transport_parsing *transport_parsing, case GRPC_DTS_FRAME: GPR_ASSERT(cur < end); if ((gpr_uint32)(end - cur) == transport_parsing->incoming_frame_size) { - if (!parse_frame_slice( - transport_parsing, - gpr_slice_sub_no_ref(slice, cur - beg, end - beg), 1)) { + if (!parse_frame_slice(transport_parsing, + gpr_slice_sub_no_ref(slice, (size_t)(cur - beg), + (size_t)(end - beg)), + 1)) { return 0; } transport_parsing->deframe_state = GRPC_DTS_FH_0; @@ -389,11 +391,12 @@ int grpc_chttp2_perform_read(grpc_chttp2_transport_parsing *transport_parsing, return 1; } else if ((gpr_uint32)(end - cur) > transport_parsing->incoming_frame_size) { + size_t cur_offset = (size_t)(cur - beg); if (!parse_frame_slice( transport_parsing, gpr_slice_sub_no_ref( - slice, cur - beg, - cur + transport_parsing->incoming_frame_size - beg), + slice, cur_offset, + cur_offset + transport_parsing->incoming_frame_size), 1)) { return 0; } @@ -401,9 +404,10 @@ int grpc_chttp2_perform_read(grpc_chttp2_transport_parsing *transport_parsing, transport_parsing->incoming_stream = NULL; goto dts_fh_0; /* loop */ } else { - if (!parse_frame_slice( - transport_parsing, - gpr_slice_sub_no_ref(slice, cur - beg, end - beg), 0)) { + if (!parse_frame_slice(transport_parsing, + gpr_slice_sub_no_ref(slice, (size_t)(cur - beg), + (size_t)(end - beg)), + 0)) { return 0; } transport_parsing->incoming_frame_size -= (end - cur); -- cgit v1.2.3 From f96dfc3cf89f0e10a5356ca1bcfd4697410a75c4 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Thu, 10 Sep 2015 14:43:18 -0700 Subject: First round of fixing up implicit 64->32 bit conversions --- Makefile | 7 +++ include/grpc/support/port_platform.h | 1 + include/grpc/support/slice_buffer.h | 2 +- src/core/channel/channel_args.c | 2 +- src/core/channel/compress_filter.c | 3 +- src/core/compression/message_compress.c | 10 ++-- src/core/iomgr/alarm.c | 4 +- src/core/iomgr/alarm_heap.c | 4 +- src/core/iomgr/tcp_client_posix.c | 3 +- src/core/iomgr/tcp_server_posix.c | 7 +-- src/core/iomgr/udp_server.c | 7 +-- src/core/iomgr/wakeup_fd_pipe.c | 2 +- src/core/security/jwt_verifier.c | 8 ++- src/core/support/slice_buffer.c | 2 +- src/core/support/stack_lockfree.c | 8 +-- src/core/surface/call.c | 14 +++--- src/core/surface/server.c | 13 +++-- src/core/transport/chttp2/frame_goaway.c | 6 ++- src/core/transport/chttp2/frame_settings.c | 2 +- src/core/transport/chttp2/hpack_parser.c | 3 +- src/core/transport/chttp2/parsing.c | 4 +- src/core/transport/chttp2/stream_encoder.c | 41 +++++++++------ src/core/transport/chttp2/timeout_encoding.c | 2 +- src/core/transport/chttp2/writing.c | 18 ++++--- src/core/transport/chttp2_transport.c | 19 ++++--- src/core/transport/transport.h | 2 +- src/core/tsi/fake_transport_security.c | 9 ++-- src/core/tsi/ssl_transport_security.c | 64 ++++++++++++++++-------- templates/Makefile.template | 7 +++ test/build/empty.c | 34 +++++++++++++ test/core/compression/message_compress_test.c | 2 +- test/core/fling/server.c | 2 +- test/core/iomgr/fd_posix_test.c | 2 +- test/core/iomgr/udp_server_test.c | 2 +- test/core/support/murmur_hash_test.c | 4 +- test/core/support/stack_lockfree_test.c | 7 +-- test/core/transport/chttp2/hpack_table_test.c | 2 +- test/core/transport/chttp2/stream_encoder_test.c | 4 +- test/core/transport/chttp2/stream_map_test.c | 40 ++++++++------- tools/codegen/core/gen_hpack_tables.c | 33 ++++++------ 40 files changed, 261 insertions(+), 145 deletions(-) create mode 100644 test/build/empty.c (limited to 'src/core/transport/chttp2/parsing.c') diff --git a/Makefile b/Makefile index 5a3f1ea741..21f3011a6e 100644 --- a/Makefile +++ b/Makefile @@ -231,6 +231,10 @@ endif 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) +# 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. # 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 @@ -246,6 +250,9 @@ DEFINES += $(EXTRA_DEFINES) endif CFLAGS += -std=c89 -pedantic -Wsign-conversion +ifeq ($(HAS_SHORTEN_64_TO_32),true) +CFLAGS += -Wshorten-64-to-32 +endif ifeq ($(HAS_CXX11),true) CXXFLAGS += -std=c++11 else diff --git a/include/grpc/support/port_platform.h b/include/grpc/support/port_platform.h index d09815557e..69709f8850 100644 --- a/include/grpc/support/port_platform.h +++ b/include/grpc/support/port_platform.h @@ -318,6 +318,7 @@ typedef uintptr_t gpr_uintptr; /* INT64_MAX is unavailable on some platforms. */ #define GPR_INT64_MAX (gpr_int64)(~(gpr_uint64)0 >> 1) +#define GPR_UINT32_MAX (~(gpr_uint32)0) /* maximum alignment needed for any type on this platform, rounded up to a power of two */ diff --git a/include/grpc/support/slice_buffer.h b/include/grpc/support/slice_buffer.h index 04db003ac5..321ba288fd 100644 --- a/include/grpc/support/slice_buffer.h +++ b/include/grpc/support/slice_buffer.h @@ -77,7 +77,7 @@ size_t gpr_slice_buffer_add_indexed(gpr_slice_buffer *sb, gpr_slice slice); void gpr_slice_buffer_addn(gpr_slice_buffer *sb, gpr_slice *slices, size_t n); /* add a very small (less than 8 bytes) amount of data to the end of a slice buffer: returns a pointer into which to add the data */ -gpr_uint8 *gpr_slice_buffer_tiny_add(gpr_slice_buffer *sb, unsigned len); +gpr_uint8 *gpr_slice_buffer_tiny_add(gpr_slice_buffer *sb, size_t len); /* pop the last buffer, but don't unref it */ void gpr_slice_buffer_pop(gpr_slice_buffer *sb); /* clear a slice buffer, unref all elements */ diff --git a/src/core/channel/channel_args.c b/src/core/channel/channel_args.c index 31ce3a83fd..591135cd6f 100644 --- a/src/core/channel/channel_args.c +++ b/src/core/channel/channel_args.c @@ -132,7 +132,7 @@ grpc_compression_algorithm grpc_channel_args_get_compression_algorithm( for (i = 0; i < a->num_args; ++i) { if (a->args[i].type == GRPC_ARG_INTEGER && !strcmp(GRPC_COMPRESSION_ALGORITHM_ARG, a->args[i].key)) { - return a->args[i].value.integer; + return (grpc_compression_algorithm)a->args[i].value.integer; break; } } diff --git a/src/core/channel/compress_filter.c b/src/core/channel/compress_filter.c index 0b85c7b4fa..8e06094257 100644 --- a/src/core/channel/compress_filter.c +++ b/src/core/channel/compress_filter.c @@ -142,8 +142,9 @@ static void finish_compressed_sopb(grpc_stream_op_buffer *send_ops, grpc_stream_op *sop = &send_ops->ops[i]; switch (sop->type) { case GRPC_OP_BEGIN_MESSAGE: + GPR_ASSERT(calld->slices.length <= GPR_UINT32_MAX); grpc_sopb_add_begin_message( - &new_send_ops, calld->slices.length, + &new_send_ops, (gpr_uint32)calld->slices.length, sop->data.begin_message.flags | GRPC_WRITE_INTERNAL_COMPRESS); break; case GRPC_OP_SLICE: diff --git a/src/core/compression/message_compress.c b/src/core/compression/message_compress.c index 7856f40dd1..01db7134c3 100644 --- a/src/core/compression/message_compress.c +++ b/src/core/compression/message_compress.c @@ -49,19 +49,23 @@ static int zlib_body(z_stream *zs, gpr_slice_buffer *input, int flush; size_t i; gpr_slice outbuf = gpr_slice_malloc(OUTPUT_BLOCK_SIZE); + const uInt uint_max = ~(uInt)0; - zs->avail_out = GPR_SLICE_LENGTH(outbuf); + GPR_ASSERT(GPR_SLICE_LENGTH(outbuf) <= uint_max); + zs->avail_out = (uInt)GPR_SLICE_LENGTH(outbuf); zs->next_out = GPR_SLICE_START_PTR(outbuf); flush = Z_NO_FLUSH; for (i = 0; i < input->count; i++) { if (i == input->count - 1) flush = Z_FINISH; - zs->avail_in = GPR_SLICE_LENGTH(input->slices[i]); + GPR_ASSERT(GPR_SLICE_LENGTH(input->slices[i]) <= uint_max); + zs->avail_in = (uInt)GPR_SLICE_LENGTH(input->slices[i]); zs->next_in = GPR_SLICE_START_PTR(input->slices[i]); do { if (zs->avail_out == 0) { gpr_slice_buffer_add_indexed(output, outbuf); outbuf = gpr_slice_malloc(OUTPUT_BLOCK_SIZE); - zs->avail_out = GPR_SLICE_LENGTH(outbuf); + GPR_ASSERT(GPR_SLICE_LENGTH(outbuf) <= uint_max); + zs->avail_out = (uInt)GPR_SLICE_LENGTH(outbuf); zs->next_out = GPR_SLICE_START_PTR(outbuf); } r = flate(zs, flush); diff --git a/src/core/iomgr/alarm.c b/src/core/iomgr/alarm.c index e31793475f..515b96ffc1 100644 --- a/src/core/iomgr/alarm.c +++ b/src/core/iomgr/alarm.c @@ -145,7 +145,7 @@ static void list_remove(grpc_alarm *alarm) { alarm->prev->next = alarm->next; } -static void swap_adjacent_shards_in_queue(size_t first_shard_queue_index) { +static void swap_adjacent_shards_in_queue(gpr_uint32 first_shard_queue_index) { shard_type *temp; temp = g_shard_queue[first_shard_queue_index]; g_shard_queue[first_shard_queue_index] = @@ -355,7 +355,7 @@ static int run_some_expired_alarms(gpr_mu *drop_mu, gpr_timespec now, gpr_mu_lock(drop_mu); } - return n; + return (int)n; } int grpc_alarm_check(gpr_mu *drop_mu, gpr_timespec now, gpr_timespec *next) { diff --git a/src/core/iomgr/alarm_heap.c b/src/core/iomgr/alarm_heap.c index 7bafdffcef..769142e425 100644 --- a/src/core/iomgr/alarm_heap.c +++ b/src/core/iomgr/alarm_heap.c @@ -45,7 +45,7 @@ its argument. */ static void adjust_upwards(grpc_alarm **first, gpr_uint32 i, grpc_alarm *t) { while (i > 0) { - gpr_uint32 parent = (i - 1u) / 2u; + gpr_uint32 parent = (gpr_uint32)(((int)i - 1) / 2); if (gpr_time_cmp(first[parent]->deadline, t->deadline) >= 0) break; first[i] = first[parent]; first[i]->heap_index = i; @@ -94,7 +94,7 @@ static void maybe_shrink(grpc_alarm_heap *heap) { static void note_changed_priority(grpc_alarm_heap *heap, grpc_alarm *alarm) { gpr_uint32 i = alarm->heap_index; - gpr_uint32 parent = (i - 1u) / 2u; + gpr_uint32 parent = (gpr_uint32)(((int)i - 1) / 2); if (gpr_time_cmp(heap->alarms[parent]->deadline, alarm->deadline) < 0) { adjust_upwards(heap->alarms, i, alarm); } else { diff --git a/src/core/iomgr/tcp_client_posix.c b/src/core/iomgr/tcp_client_posix.c index 7ca0a60c31..c3668f6a92 100644 --- a/src/core/iomgr/tcp_client_posix.c +++ b/src/core/iomgr/tcp_client_posix.c @@ -229,7 +229,8 @@ void grpc_tcp_client_connect(void (*cb)(void *arg, grpc_endpoint *ep), } do { - err = connect(fd, addr, addr_len); + GPR_ASSERT(addr_len < ~(socklen_t)0); + err = connect(fd, addr, (socklen_t)addr_len); } while (err < 0 && errno == EINTR); addr_str = grpc_sockaddr_to_uri(addr); diff --git a/src/core/iomgr/tcp_server_posix.c b/src/core/iomgr/tcp_server_posix.c index 6b81090108..bcbd0afe6b 100644 --- a/src/core/iomgr/tcp_server_posix.c +++ b/src/core/iomgr/tcp_server_posix.c @@ -83,7 +83,7 @@ typedef struct { struct sockaddr sockaddr; struct sockaddr_un un; } addr; - int addr_len; + size_t addr_len; grpc_iomgr_closure read_closure; grpc_iomgr_closure destroyed_closure; } server_port; @@ -236,7 +236,7 @@ static void init_max_accept_queue_size(void) { char *end; long i = strtol(buf, &end, 10); if (i > 0 && i <= INT_MAX && end && *end == 0) { - n = i; + n = (int)i; } } fclose(fp); @@ -274,7 +274,8 @@ static int prepare_socket(int fd, const struct sockaddr *addr, goto error; } - if (bind(fd, addr, addr_len) < 0) { + GPR_ASSERT(addr_len < ~(socklen_t)0); + if (bind(fd, addr, (socklen_t)addr_len) < 0) { char *addr_str; grpc_sockaddr_to_string(&addr_str, addr, 0); gpr_log(GPR_ERROR, "bind addr=%s: %s", addr_str, strerror(errno)); diff --git a/src/core/iomgr/udp_server.c b/src/core/iomgr/udp_server.c index 95ae698781..ed9eee8726 100644 --- a/src/core/iomgr/udp_server.c +++ b/src/core/iomgr/udp_server.c @@ -78,7 +78,7 @@ typedef struct { struct sockaddr sockaddr; struct sockaddr_un un; } addr; - int addr_len; + size_t addr_len; grpc_iomgr_closure read_closure; grpc_iomgr_closure destroyed_closure; grpc_udp_server_read_cb read_cb; @@ -242,7 +242,8 @@ static int prepare_socket(int fd, const struct sockaddr *addr, #endif } - if (bind(fd, addr, addr_len) < 0) { + GPR_ASSERT(addr_len < ~(socklen_t)0); + if (bind(fd, addr, (socklen_t)addr_len) < 0) { char *addr_str; grpc_sockaddr_to_string(&addr_str, addr, 0); gpr_log(GPR_ERROR, "bind addr=%s: %s", addr_str, strerror(errno)); @@ -431,7 +432,7 @@ void grpc_udp_server_start(grpc_udp_server *s, grpc_pollset **pollsets, /* TODO(rjshade): Add a test for this method. */ void grpc_udp_server_write(server_port *sp, const char *buffer, size_t buf_len, const struct sockaddr *peer_address) { - int rc; + ssize_t rc; rc = sendto(sp->fd, buffer, buf_len, 0, peer_address, sizeof(peer_address)); if (rc < 0) { gpr_log(GPR_ERROR, "Unable to send data: %s", strerror(errno)); diff --git a/src/core/iomgr/wakeup_fd_pipe.c b/src/core/iomgr/wakeup_fd_pipe.c index bd643e8061..902034ee4b 100644 --- a/src/core/iomgr/wakeup_fd_pipe.c +++ b/src/core/iomgr/wakeup_fd_pipe.c @@ -56,7 +56,7 @@ static void pipe_init(grpc_wakeup_fd *fd_info) { static void pipe_consume(grpc_wakeup_fd *fd_info) { char buf[128]; - int r; + ssize_t r; for (;;) { r = read(fd_info->read_fd, buf, sizeof(buf)); diff --git a/src/core/security/jwt_verifier.c b/src/core/security/jwt_verifier.c index 03f8c3783e..790f2178db 100644 --- a/src/core/security/jwt_verifier.c +++ b/src/core/security/jwt_verifier.c @@ -33,6 +33,7 @@ #include "src/core/security/jwt_verifier.h" +#include #include #include "src/core/httpcli/httpcli.h" @@ -412,7 +413,9 @@ static EVP_PKEY *extract_pkey_from_x509(const char *x509_str) { X509 *x509 = NULL; EVP_PKEY *result = NULL; BIO *bio = BIO_new(BIO_s_mem()); - BIO_write(bio, x509_str, strlen(x509_str)); + size_t len = strlen(x509_str); + GPR_ASSERT(len < INT_MAX); + BIO_write(bio, x509_str, (int)len); x509 = PEM_read_bio_X509(bio, NULL, NULL, NULL); if (x509 == NULL) { gpr_log(GPR_ERROR, "Unable to parse x509 cert."); @@ -439,7 +442,8 @@ static BIGNUM *bignum_from_base64(const char *b64) { gpr_log(GPR_ERROR, "Invalid base64 for big num."); return NULL; } - result = BN_bin2bn(GPR_SLICE_START_PTR(bin), GPR_SLICE_LENGTH(bin), NULL); + result = + BN_bin2bn(GPR_SLICE_START_PTR(bin), (int)GPR_SLICE_LENGTH(bin), NULL); gpr_slice_unref(bin); return result; } diff --git a/src/core/support/slice_buffer.c b/src/core/support/slice_buffer.c index 6482ef9c9f..8873d459d5 100644 --- a/src/core/support/slice_buffer.c +++ b/src/core/support/slice_buffer.c @@ -69,7 +69,7 @@ void gpr_slice_buffer_destroy(gpr_slice_buffer *sb) { } } -gpr_uint8 *gpr_slice_buffer_tiny_add(gpr_slice_buffer *sb, unsigned n) { +gpr_uint8 *gpr_slice_buffer_tiny_add(gpr_slice_buffer *sb, size_t n) { gpr_slice *back; gpr_uint8 *out; diff --git a/src/core/support/stack_lockfree.c b/src/core/support/stack_lockfree.c index 0d4b4bedd9..180ba19c68 100644 --- a/src/core/support/stack_lockfree.c +++ b/src/core/support/stack_lockfree.c @@ -123,13 +123,13 @@ int gpr_stack_lockfree_push(gpr_stack_lockfree *stack, int entry) { #ifndef NDEBUG /* Check for double push */ { - int pushed_index = entry / (8 * sizeof(gpr_atm)); - int pushed_bit = entry % (8 * sizeof(gpr_atm)); + int pushed_index = entry / (int)(8 * sizeof(gpr_atm)); + int pushed_bit = entry % (int)(8 * sizeof(gpr_atm)); gpr_atm old_val; old_val = gpr_atm_no_barrier_fetch_add(&stack->pushed[pushed_index], (gpr_atm)(1UL << pushed_bit)); - GPR_ASSERT((old_val & (1UL << pushed_bit)) == 0); + GPR_ASSERT((old_val & (gpr_atm)(1UL << pushed_bit)) == 0); } #endif @@ -167,7 +167,7 @@ int gpr_stack_lockfree_pop(gpr_stack_lockfree *stack) { old_val = gpr_atm_no_barrier_fetch_add(&stack->pushed[pushed_index], -(gpr_atm)(1UL << pushed_bit)); - GPR_ASSERT((old_val & (1UL << pushed_bit)) != 0); + GPR_ASSERT((old_val & (gpr_atm)(1UL << pushed_bit)) != 0); } #endif diff --git a/src/core/surface/call.c b/src/core/surface/call.c index 6ece56371b..c96df77a98 100644 --- a/src/core/surface/call.c +++ b/src/core/surface/call.c @@ -508,7 +508,7 @@ static void set_status_code(grpc_call *call, status_source source, if (call->status[source].is_set) return; call->status[source].is_set = 1; - call->status[source].code = status; + call->status[source].code = (grpc_status_code)status; call->error_status_set = status != GRPC_STATUS_OK; if (status != GRPC_STATUS_OK && !grpc_bbq_empty(&call->incoming_queue)) { @@ -604,7 +604,7 @@ static void unlock(grpc_call *call) { int completing_requests = 0; int start_op = 0; int i; - const gpr_uint32 MAX_RECV_PEEK_AHEAD = 65536; + const size_t MAX_RECV_PEEK_AHEAD = 65536; size_t buffered_bytes; int cancel_alarm = 0; @@ -1107,10 +1107,12 @@ static int fill_send_ops(grpc_call *call, grpc_transport_stream_op *op) { /* fall through intended */ case WRITE_STATE_STARTED: if (is_op_live(call, GRPC_IOREQ_SEND_MESSAGE)) { + size_t length; data = call->request_data[GRPC_IOREQ_SEND_MESSAGE]; flags = call->request_flags[GRPC_IOREQ_SEND_MESSAGE]; - grpc_sopb_add_begin_message( - &call->send_ops, grpc_byte_buffer_length(data.send_message), flags); + length = grpc_byte_buffer_length(data.send_message); + GPR_ASSERT(length <= GPR_UINT32_MAX); + grpc_sopb_add_begin_message(&call->send_ops, (gpr_uint32)length, flags); copy_byte_buffer_to_stream_ops(data.send_message, &call->send_ops); op->send_ops = &call->send_ops; call->last_send_contains |= 1 << GRPC_IOREQ_SEND_MESSAGE; @@ -1243,7 +1245,7 @@ static grpc_call_error start_ioreq(grpc_call *call, const grpc_ioreq *reqs, } if (op == GRPC_IOREQ_SEND_STATUS) { set_status_code(call, STATUS_FROM_SERVER_STATUS, - reqs[i].data.send_status.code); + (gpr_uint32)reqs[i].data.send_status.code); if (reqs[i].data.send_status.details) { set_status_details(call, STATUS_FROM_SERVER_STATUS, GRPC_MDSTR_REF(reqs[i].data.send_status.details)); @@ -1333,7 +1335,7 @@ static grpc_call_error cancel_with_status(grpc_call *c, grpc_status_code status, GPR_ASSERT(status != GRPC_STATUS_OK); - set_status_code(c, STATUS_FROM_API_OVERRIDE, status); + set_status_code(c, STATUS_FROM_API_OVERRIDE, (gpr_uint32)status); set_status_details(c, STATUS_FROM_API_OVERRIDE, details); c->cancel_with_status = status; diff --git a/src/core/surface/server.c b/src/core/surface/server.c index c3d8046787..3d404f78a4 100644 --- a/src/core/surface/server.c +++ b/src/core/surface/server.c @@ -33,6 +33,7 @@ #include "src/core/surface/server.h" +#include #include #include @@ -804,7 +805,7 @@ grpc_server *grpc_server_create_from_filters( server->request_freelist = gpr_stack_lockfree_create(server->max_requested_calls); for (i = 0; i < (size_t)server->max_requested_calls; i++) { - gpr_stack_lockfree_push(server->request_freelist, i); + gpr_stack_lockfree_push(server->request_freelist, (int)i); } request_matcher_init(&server->unregistered_request_matcher, server->max_requested_calls); @@ -896,7 +897,7 @@ void grpc_server_setup_transport(grpc_server *s, grpc_transport *transport, grpc_mdstr *host; grpc_mdstr *method; gpr_uint32 hash; - gpr_uint32 slots; + size_t slots; gpr_uint32 probes; gpr_uint32 max_probes = 0; grpc_transport_op op; @@ -949,7 +950,8 @@ void grpc_server_setup_transport(grpc_server *s, grpc_transport *transport, crm->host = host; crm->method = method; } - chand->registered_method_slots = slots; + GPR_ASSERT(slots <= GPR_UINT32_MAX); + chand->registered_method_slots = (gpr_uint32)slots; chand->registered_method_max_probes = max_probes; } @@ -970,7 +972,7 @@ void grpc_server_setup_transport(grpc_server *s, grpc_transport *transport, op.set_accept_stream_user_data = chand; op.on_connectivity_state_change = &chand->channel_connectivity_changed; op.connectivity_state = &chand->connectivity_state; - op.disconnect = gpr_atm_acq_load(&s->shutdown_flag); + op.disconnect = gpr_atm_acq_load(&s->shutdown_flag) != 0; grpc_transport_perform_op(transport, &op); } @@ -1256,8 +1258,9 @@ static void done_request_event(void *req, grpc_cq_completion *c) { if (rc >= server->requested_calls && rc < server->requested_calls + server->max_requested_calls) { + GPR_ASSERT(rc - server->requested_calls <= INT_MAX); gpr_stack_lockfree_push(server->request_freelist, - rc - server->requested_calls); + (int)(rc - server->requested_calls)); } else { gpr_free(req); } diff --git a/src/core/transport/chttp2/frame_goaway.c b/src/core/transport/chttp2/frame_goaway.c index d40e6fd03a..1a6d80da58 100644 --- a/src/core/transport/chttp2/frame_goaway.c +++ b/src/core/transport/chttp2/frame_goaway.c @@ -143,7 +143,7 @@ grpc_chttp2_parse_error grpc_chttp2_goaway_parser_parse( transport_parsing->goaway_received = 1; transport_parsing->goaway_last_stream_index = p->last_stream_id; gpr_slice_unref(transport_parsing->goaway_text); - transport_parsing->goaway_error = p->error_code; + transport_parsing->goaway_error = (grpc_status_code)p->error_code; transport_parsing->goaway_text = gpr_slice_new(p->debug_data, p->debug_length, gpr_free); p->debug_data = NULL; @@ -160,7 +160,9 @@ void grpc_chttp2_goaway_append(gpr_uint32 last_stream_id, gpr_uint32 error_code, gpr_slice_buffer *slice_buffer) { gpr_slice header = gpr_slice_malloc(9 + 4 + 4); gpr_uint8 *p = GPR_SLICE_START_PTR(header); - gpr_uint32 frame_length = 4 + 4 + GPR_SLICE_LENGTH(debug_data); + gpr_uint32 frame_length; + GPR_ASSERT(GPR_SLICE_LENGTH(debug_data) < GPR_UINT32_MAX - 4 - 4); + frame_length = 4 + 4 + (gpr_uint32)GPR_SLICE_LENGTH(debug_data); /* frame header: length */ *p++ = frame_length >> 16; diff --git a/src/core/transport/chttp2/frame_settings.c b/src/core/transport/chttp2/frame_settings.c index 927ae55996..f70776bf4c 100644 --- a/src/core/transport/chttp2/frame_settings.c +++ b/src/core/transport/chttp2/frame_settings.c @@ -76,7 +76,7 @@ static gpr_uint8 *fill_header(gpr_uint8 *out, gpr_uint32 length, gpr_slice grpc_chttp2_settings_create(gpr_uint32 *old, const gpr_uint32 *new, gpr_uint32 force_mask, size_t count) { size_t i; - size_t n = 0; + gpr_uint32 n = 0; gpr_slice output; gpr_uint8 *p; diff --git a/src/core/transport/chttp2/hpack_parser.c b/src/core/transport/chttp2/hpack_parser.c index f806f59ed7..93a452f1fd 100644 --- a/src/core/transport/chttp2/hpack_parser.c +++ b/src/core/transport/chttp2/hpack_parser.c @@ -1085,7 +1085,8 @@ static int parse_string_prefix(grpc_chttp2_hpack_parser *p, static void append_bytes(grpc_chttp2_hpack_parser_string *str, const gpr_uint8 *data, size_t length) { if (length + str->length > str->capacity) { - str->capacity = str->length + length; + GPR_ASSERT(str->length + length <= GPR_UINT32_MAX); + str->capacity = (gpr_uint32)(str->length + length); str->str = gpr_realloc(str->str, str->capacity); } memcpy(str->str + str->length, data, length); diff --git a/src/core/transport/chttp2/parsing.c b/src/core/transport/chttp2/parsing.c index b0f884e258..a29987a05a 100644 --- a/src/core/transport/chttp2/parsing.c +++ b/src/core/transport/chttp2/parsing.c @@ -131,7 +131,7 @@ void grpc_chttp2_publish_reads( published later */ if (transport_parsing->goaway_received) { grpc_chttp2_add_incoming_goaway(transport_global, - transport_parsing->goaway_error, + (gpr_uint32)transport_parsing->goaway_error, transport_parsing->goaway_text); transport_parsing->goaway_text = gpr_empty_slice(); transport_parsing->goaway_received = 0; @@ -212,7 +212,7 @@ void grpc_chttp2_publish_reads( if (stream_parsing->saw_rst_stream) { stream_global->cancelled = 1; stream_global->cancelled_status = grpc_chttp2_http2_error_to_grpc_status( - stream_parsing->rst_stream_reason); + (grpc_chttp2_error_code)stream_parsing->rst_stream_reason); if (stream_parsing->rst_stream_reason == GRPC_CHTTP2_NO_ERROR) { stream_global->published_cancelled = 1; } diff --git a/src/core/transport/chttp2/stream_encoder.c b/src/core/transport/chttp2/stream_encoder.c index bcae93dc7a..8c30af652f 100644 --- a/src/core/transport/chttp2/stream_encoder.c +++ b/src/core/transport/chttp2/stream_encoder.c @@ -74,8 +74,9 @@ typedef struct { } framer_state; /* fills p (which is expected to be 9 bytes long) with a data frame header */ -static void fill_header(gpr_uint8 *p, gpr_uint8 type, gpr_uint32 id, - gpr_uint32 len, gpr_uint8 flags) { +static void fill_header(gpr_uint8 *p, gpr_uint8 type, gpr_uint32 id, size_t len, + gpr_uint8 flags) { + GPR_ASSERT(len < 16777316); *p++ = len >> 16; *p++ = len >> 8; *p++ = len; @@ -185,8 +186,8 @@ static grpc_mdelem *add_elem(grpc_chttp2_hpack_compressor *c, gpr_uint32 key_hash = elem->key->hash; gpr_uint32 elem_hash = GRPC_MDSTR_KV_HASH(key_hash, elem->value->hash); gpr_uint32 new_index = c->tail_remote_index + c->table_elems + 1; - gpr_uint32 elem_size = 32 + GPR_SLICE_LENGTH(elem->key->slice) + - GPR_SLICE_LENGTH(elem->value->slice); + size_t elem_size = 32 + GPR_SLICE_LENGTH(elem->key->slice) + + GPR_SLICE_LENGTH(elem->value->slice); grpc_mdelem *elem_to_unref; /* Reserve space for this element in the remote table: if this overflows @@ -270,7 +271,7 @@ static grpc_mdelem *add_elem(grpc_chttp2_hpack_compressor *c, static void emit_indexed(grpc_chttp2_hpack_compressor *c, gpr_uint32 index, framer_state *st) { - size_t len = GRPC_CHTTP2_VARINT_LENGTH(index, 1); + gpr_uint32 len = GRPC_CHTTP2_VARINT_LENGTH(index, 1); GRPC_CHTTP2_WRITE_VARINT(index, 1, 0x80, add_tiny_header_data(st, len), len); } @@ -291,11 +292,13 @@ static void emit_lithdr_incidx(grpc_chttp2_hpack_compressor *c, gpr_uint32 len_pfx = GRPC_CHTTP2_VARINT_LENGTH(key_index, 2); gpr_uint8 huffman_prefix; gpr_slice value_slice = get_wire_value(elem, &huffman_prefix); - gpr_uint32 len_val = GPR_SLICE_LENGTH(value_slice); - gpr_uint32 len_val_len = GRPC_CHTTP2_VARINT_LENGTH(len_val, 1); + size_t len_val = GPR_SLICE_LENGTH(value_slice); + gpr_uint32 len_val_len; + GPR_ASSERT(len_val <= GPR_UINT32_MAX); + len_val_len = GRPC_CHTTP2_VARINT_LENGTH((gpr_uint32)len_val, 1); GRPC_CHTTP2_WRITE_VARINT(key_index, 2, 0x40, add_tiny_header_data(st, len_pfx), len_pfx); - GRPC_CHTTP2_WRITE_VARINT(len_val, 1, 0x00, + GRPC_CHTTP2_WRITE_VARINT((gpr_uint32)len_val, 1, 0x00, add_tiny_header_data(st, len_val_len), len_val_len); add_header_data(st, gpr_slice_ref(value_slice)); } @@ -306,23 +309,27 @@ static void emit_lithdr_noidx(grpc_chttp2_hpack_compressor *c, gpr_uint32 len_pfx = GRPC_CHTTP2_VARINT_LENGTH(key_index, 4); gpr_uint8 huffman_prefix; gpr_slice value_slice = get_wire_value(elem, &huffman_prefix); - gpr_uint32 len_val = GPR_SLICE_LENGTH(value_slice); - gpr_uint32 len_val_len = GRPC_CHTTP2_VARINT_LENGTH(len_val, 1); + size_t len_val = GPR_SLICE_LENGTH(value_slice); + gpr_uint32 len_val_len; + GPR_ASSERT(len_val <= GPR_UINT32_MAX); + len_val_len = GRPC_CHTTP2_VARINT_LENGTH((gpr_uint32)len_val, 1); GRPC_CHTTP2_WRITE_VARINT(key_index, 4, 0x00, add_tiny_header_data(st, len_pfx), len_pfx); - GRPC_CHTTP2_WRITE_VARINT(len_val, 1, 0x00, + GRPC_CHTTP2_WRITE_VARINT((gpr_uint32)len_val, 1, 0x00, add_tiny_header_data(st, len_val_len), len_val_len); add_header_data(st, gpr_slice_ref(value_slice)); } static void emit_lithdr_incidx_v(grpc_chttp2_hpack_compressor *c, grpc_mdelem *elem, framer_state *st) { - gpr_uint32 len_key = GPR_SLICE_LENGTH(elem->key->slice); + gpr_uint32 len_key = (gpr_uint32)GPR_SLICE_LENGTH(elem->key->slice); gpr_uint8 huffman_prefix; gpr_slice value_slice = get_wire_value(elem, &huffman_prefix); - gpr_uint32 len_val = GPR_SLICE_LENGTH(value_slice); + gpr_uint32 len_val = (gpr_uint32)GPR_SLICE_LENGTH(value_slice); gpr_uint32 len_key_len = GRPC_CHTTP2_VARINT_LENGTH(len_key, 1); gpr_uint32 len_val_len = GRPC_CHTTP2_VARINT_LENGTH(len_val, 1); + GPR_ASSERT(len_key <= GPR_UINT32_MAX); + GPR_ASSERT(GPR_SLICE_LENGTH(value_slice) <= GPR_UINT32_MAX); *add_tiny_header_data(st, 1) = 0x40; GRPC_CHTTP2_WRITE_VARINT(len_key, 1, 0x00, add_tiny_header_data(st, len_key_len), len_key_len); @@ -334,12 +341,14 @@ static void emit_lithdr_incidx_v(grpc_chttp2_hpack_compressor *c, static void emit_lithdr_noidx_v(grpc_chttp2_hpack_compressor *c, grpc_mdelem *elem, framer_state *st) { - gpr_uint32 len_key = GPR_SLICE_LENGTH(elem->key->slice); + gpr_uint32 len_key = (gpr_uint32)GPR_SLICE_LENGTH(elem->key->slice); gpr_uint8 huffman_prefix; gpr_slice value_slice = get_wire_value(elem, &huffman_prefix); - gpr_uint32 len_val = GPR_SLICE_LENGTH(value_slice); + gpr_uint32 len_val = (gpr_uint32)GPR_SLICE_LENGTH(value_slice); gpr_uint32 len_key_len = GRPC_CHTTP2_VARINT_LENGTH(len_key, 1); gpr_uint32 len_val_len = GRPC_CHTTP2_VARINT_LENGTH(len_val, 1); + GPR_ASSERT(len_key <= GPR_UINT32_MAX); + GPR_ASSERT(GPR_SLICE_LENGTH(value_slice) <= GPR_UINT32_MAX); *add_tiny_header_data(st, 1) = 0x00; GRPC_CHTTP2_WRITE_VARINT(len_key, 1, 0x00, add_tiny_header_data(st, len_key_len), len_key_len); @@ -565,7 +574,7 @@ void grpc_chttp2_encode(grpc_stream_op *ops, size_t ops_count, int eof, framer_state st; gpr_slice slice; grpc_stream_op *op; - gpr_uint32 max_take_size; + size_t max_take_size; gpr_uint32 curop = 0; gpr_uint32 unref_op; grpc_mdctx *mdctx = compressor->mdctx; diff --git a/src/core/transport/chttp2/timeout_encoding.c b/src/core/transport/chttp2/timeout_encoding.c index 40fcdc26dc..8a9b290ecb 100644 --- a/src/core/transport/chttp2/timeout_encoding.c +++ b/src/core/transport/chttp2/timeout_encoding.c @@ -123,7 +123,7 @@ void grpc_chttp2_encode_timeout(gpr_timespec timeout, char *buffer) { enc_nanos(buffer, timeout.tv_nsec); } else if (timeout.tv_sec < 1000 && timeout.tv_nsec != 0) { enc_micros(buffer, - timeout.tv_sec * 1000000 + + (int)(timeout.tv_sec * 1000000) + (timeout.tv_nsec / 1000 + (timeout.tv_nsec % 1000 != 0))); } else { enc_seconds(buffer, timeout.tv_sec + (timeout.tv_nsec != 0)); diff --git a/src/core/transport/chttp2/writing.c b/src/core/transport/chttp2/writing.c index ac79044e08..c015e82931 100644 --- a/src/core/transport/chttp2/writing.c +++ b/src/core/transport/chttp2/writing.c @@ -32,10 +32,13 @@ */ #include "src/core/transport/chttp2/internal.h" -#include "src/core/transport/chttp2/http2_errors.h" + +#include #include +#include "src/core/transport/chttp2/http2_errors.h" + static void finalize_outbuf(grpc_chttp2_transport_writing *transport_writing); int grpc_chttp2_unlocking_check_writes( @@ -78,12 +81,13 @@ int grpc_chttp2_unlocking_check_writes( stream_writing->send_closed = GRPC_DONT_SEND_CLOSED; if (stream_global->outgoing_sopb) { - window_delta = - grpc_chttp2_preencode(stream_global->outgoing_sopb->ops, - &stream_global->outgoing_sopb->nops, - GPR_MIN(transport_global->outgoing_window, - stream_global->outgoing_window), - &stream_writing->sopb); + window_delta = grpc_chttp2_preencode( + stream_global->outgoing_sopb->ops, + &stream_global->outgoing_sopb->nops, + (gpr_uint32)GPR_MIN(GPR_MIN(transport_global->outgoing_window, + stream_global->outgoing_window), + GPR_UINT32_MAX), + &stream_writing->sopb); GRPC_CHTTP2_FLOWCTL_TRACE_TRANSPORT( "write", transport_global, outgoing_window, -(gpr_int64)window_delta); GRPC_CHTTP2_FLOWCTL_TRACE_STREAM("write", transport_global, stream_global, diff --git a/src/core/transport/chttp2_transport.c b/src/core/transport/chttp2_transport.c index c1a3c0436f..c80330527e 100644 --- a/src/core/transport/chttp2_transport.c +++ b/src/core/transport/chttp2_transport.c @@ -692,7 +692,8 @@ static void perform_stream_op_locked( op->max_recv_bytes - stream_global->max_recv_bytes); stream_global->unannounced_incoming_window += op->max_recv_bytes - stream_global->max_recv_bytes; - stream_global->max_recv_bytes = op->max_recv_bytes; + stream_global->max_recv_bytes = + (gpr_uint32)(GPR_MIN(op->max_recv_bytes, GPR_UINT32_MAX)); } grpc_chttp2_incoming_metadata_live_op_buffer_end( &stream_global->outstanding_metadata); @@ -761,7 +762,7 @@ static void perform_transport_op(grpc_transport *gt, grpc_transport_op *op) { t->global.sent_goaway = 1; grpc_chttp2_goaway_append( t->global.last_incoming_stream_id, - grpc_chttp2_grpc_status_to_http2_error(op->goaway_status), + (gpr_uint32)grpc_chttp2_grpc_status_to_http2_error(op->goaway_status), gpr_slice_ref(*op->goaway_message), &t->global.qbuf); close_transport = !grpc_chttp2_has_streams(t); } @@ -829,8 +830,9 @@ static void remove_stream(grpc_chttp2_transport *t, gpr_uint32 id) { new_stream_count = grpc_chttp2_stream_map_size(&t->parsing_stream_map) + grpc_chttp2_stream_map_size(&t->new_stream_map); + GPR_ASSERT(new_stream_count <= GPR_UINT32_MAX); if (new_stream_count != t->global.concurrent_stream_count) { - t->global.concurrent_stream_count = new_stream_count; + t->global.concurrent_stream_count = (gpr_uint32)new_stream_count; maybe_start_some_streams(&t->global); } } @@ -943,7 +945,8 @@ static void cancel_from_api(grpc_chttp2_transport_global *transport_global, gpr_slice_buffer_add( &transport_global->qbuf, grpc_chttp2_rst_stream_create( - stream_global->id, grpc_chttp2_grpc_status_to_http2_error(status))); + stream_global->id, + (gpr_uint32)grpc_chttp2_grpc_status_to_http2_error(status))); } grpc_chttp2_list_add_read_write_state_changed(transport_global, stream_global); @@ -989,11 +992,11 @@ static void close_from_api(grpc_chttp2_transport_global *transport_global, *p++ = 's'; if (status < 10) { *p++ = 1; - *p++ = '0' + status; + *p++ = (gpr_uint8)('0' + status); } else { *p++ = 2; - *p++ = '0' + (status / 10); - *p++ = '0' + (status % 10); + *p++ = (gpr_uint8)('0' + (status / 10)); + *p++ = (gpr_uint8)('0' + (status % 10)); } GPR_ASSERT(p == GPR_SLICE_END_PTR(status_hdr)); len += GPR_SLICE_LENGTH(status_hdr); @@ -1121,7 +1124,7 @@ static int recv_data_loop(grpc_chttp2_transport *t, int *success) { grpc_chttp2_stream_map_move_into(&t->new_stream_map, &t->parsing_stream_map); t->global.concurrent_stream_count = - grpc_chttp2_stream_map_size(&t->parsing_stream_map); + (gpr_uint32)grpc_chttp2_stream_map_size(&t->parsing_stream_map); if (t->parsing.initial_window_update != 0) { grpc_chttp2_stream_map_for_each(&t->parsing_stream_map, update_global_window, t); diff --git a/src/core/transport/transport.h b/src/core/transport/transport.h index 92c1f38c5e..6e1ec2f64c 100644 --- a/src/core/transport/transport.h +++ b/src/core/transport/transport.h @@ -75,7 +75,7 @@ typedef struct grpc_transport_stream_op { /** The number of bytes this peer is currently prepared to receive. These bytes will be eventually used to replenish per-stream flow control windows. */ - gpr_uint32 max_recv_bytes; + size_t max_recv_bytes; grpc_iomgr_closure *on_done_recv; grpc_pollset *bind_pollset; diff --git a/src/core/tsi/fake_transport_security.c b/src/core/tsi/fake_transport_security.c index a813c30221..b1a975155a 100644 --- a/src/core/tsi/fake_transport_security.c +++ b/src/core/tsi/fake_transport_security.c @@ -100,7 +100,7 @@ static const char* tsi_fake_handshake_message_to_string(int msg) { static tsi_result tsi_fake_handshake_message_from_string( const char* msg_string, tsi_fake_handshake_message* msg) { - int i; + tsi_fake_handshake_message i; for (i = 0; i < TSI_FAKE_HANDSHAKE_MESSAGE_MAX; i++) { if (strncmp(msg_string, tsi_fake_handshake_message_strings[i], strlen(tsi_fake_handshake_message_strings[i])) == 0) { @@ -219,7 +219,7 @@ static tsi_result bytes_to_frame(unsigned char* bytes, size_t bytes_size, frame->offset = 0; frame->size = bytes_size + TSI_FAKE_FRAME_HEADER_SIZE; if (!tsi_fake_frame_ensure_size(frame)) return TSI_OUT_OF_RESOURCES; - store32_little_endian(frame->size, frame->data); + store32_little_endian((gpr_uint32)frame->size, frame->data); memcpy(frame->data + TSI_FAKE_FRAME_HEADER_SIZE, bytes, bytes_size); tsi_fake_frame_reset(frame, 1 /* needs draining */); return TSI_OK; @@ -266,7 +266,7 @@ static tsi_result fake_protector_protect(tsi_frame_protector* self, if (frame->size == 0) { /* New frame, create a header. */ size_t written_in_frame_size = 0; - store32_little_endian(impl->max_frame_size, frame_header); + store32_little_endian((gpr_uint32)impl->max_frame_size, frame_header); written_in_frame_size = TSI_FAKE_FRAME_HEADER_SIZE; result = fill_frame_from_bytes(frame_header, &written_in_frame_size, frame); if (result != TSI_INCOMPLETE_DATA) { @@ -303,7 +303,8 @@ static tsi_result fake_protector_protect_flush( frame->size = frame->offset; frame->offset = 0; frame->needs_draining = 1; - store32_little_endian(frame->size, frame->data); /* Overwrite header. */ + store32_little_endian((gpr_uint32)frame->size, + frame->data); /* Overwrite header. */ } result = drain_frame_to_bytes(protected_output_frames, protected_output_frames_size, frame); diff --git a/src/core/tsi/ssl_transport_security.c b/src/core/tsi/ssl_transport_security.c index 6add492865..99ce7ecadf 100644 --- a/src/core/tsi/ssl_transport_security.c +++ b/src/core/tsi/ssl_transport_security.c @@ -291,7 +291,7 @@ static tsi_result add_subject_alt_names_properties_to_peer( for (i = 0; i < subject_alt_name_count; i++) { GENERAL_NAME* subject_alt_name = - sk_GENERAL_NAME_value(subject_alt_names, i); + sk_GENERAL_NAME_value(subject_alt_names, (int)i); /* Filter out the non-dns entries names. */ if (subject_alt_name->type == GEN_DNS) { unsigned char* dns_name = NULL; @@ -366,7 +366,10 @@ static void log_ssl_error_stack(void) { /* Performs an SSL_read and handle errors. */ static tsi_result do_ssl_read(SSL* ssl, unsigned char* unprotected_bytes, size_t* unprotected_bytes_size) { - int read_from_ssl = SSL_read(ssl, unprotected_bytes, *unprotected_bytes_size); + int read_from_ssl; + GPR_ASSERT(*unprotected_bytes_size <= INT_MAX); + read_from_ssl = + SSL_read(ssl, unprotected_bytes, (int)*unprotected_bytes_size); if (read_from_ssl == 0) { gpr_log(GPR_ERROR, "SSL_read returned 0 unexpectedly."); return TSI_INTERNAL_ERROR; @@ -400,8 +403,10 @@ static tsi_result do_ssl_read(SSL* ssl, unsigned char* unprotected_bytes, /* Performs an SSL_write and handle errors. */ static tsi_result do_ssl_write(SSL* ssl, unsigned char* unprotected_bytes, size_t unprotected_bytes_size) { - int ssl_write_result = - SSL_write(ssl, unprotected_bytes, unprotected_bytes_size); + int ssl_write_result; + GPR_ASSERT(unprotected_bytes_size <= INT_MAX); + ssl_write_result = + SSL_write(ssl, unprotected_bytes, (int)unprotected_bytes_size); if (ssl_write_result < 0) { ssl_write_result = SSL_get_error(ssl, ssl_write_result); if (ssl_write_result == SSL_ERROR_WANT_READ) { @@ -423,7 +428,9 @@ static tsi_result ssl_ctx_use_certificate_chain( size_t pem_cert_chain_size) { tsi_result result = TSI_OK; X509* certificate = NULL; - BIO* pem = BIO_new_mem_buf((void*)pem_cert_chain, pem_cert_chain_size); + BIO* pem; + GPR_ASSERT(pem_cert_chain_size <= INT_MAX); + pem = BIO_new_mem_buf((void*)pem_cert_chain, (int)pem_cert_chain_size); if (pem == NULL) return TSI_OUT_OF_RESOURCES; do { @@ -464,7 +471,9 @@ static tsi_result ssl_ctx_use_private_key(SSL_CTX* context, size_t pem_key_size) { tsi_result result = TSI_OK; EVP_PKEY* private_key = NULL; - BIO* pem = BIO_new_mem_buf((void*)pem_key, pem_key_size); + BIO* pem; + GPR_ASSERT(pem_key_size <= INT_MAX); + pem = BIO_new_mem_buf((void*)pem_key, (int)pem_key_size); if (pem == NULL) return TSI_OUT_OF_RESOURCES; do { private_key = PEM_read_bio_PrivateKey(pem, NULL, NULL, ""); @@ -491,8 +500,11 @@ static tsi_result ssl_ctx_load_verification_certs( size_t num_roots = 0; X509* root = NULL; X509_NAME* root_name = NULL; - BIO* pem = BIO_new_mem_buf((void*)pem_roots, pem_roots_size); - X509_STORE* root_store = SSL_CTX_get_cert_store(context); + BIO* pem; + X509_STORE* root_store; + GPR_ASSERT(pem_roots_size <= INT_MAX); + pem = BIO_new_mem_buf((void*)pem_roots, (int)pem_roots_size); + root_store = SSL_CTX_get_cert_store(context); if (root_store == NULL) return TSI_INVALID_ARGUMENT; if (pem == NULL) return TSI_OUT_OF_RESOURCES; if (root_names != NULL) { @@ -592,7 +604,9 @@ static tsi_result extract_x509_subject_names_from_pem_cert( const unsigned char* pem_cert, size_t pem_cert_size, tsi_peer* peer) { tsi_result result = TSI_OK; X509* cert = NULL; - BIO* pem = BIO_new_mem_buf((void*)pem_cert, pem_cert_size); + BIO* pem; + GPR_ASSERT(pem_cert_size <= INT_MAX); + pem = BIO_new_mem_buf((void*)pem_cert, (int)pem_cert_size); if (pem == NULL) return TSI_OUT_OF_RESOURCES; cert = PEM_read_bio_X509(pem, NULL, NULL, ""); @@ -657,8 +671,9 @@ static tsi_result ssl_protector_protect(tsi_frame_protector* self, int pending_in_ssl = BIO_pending(impl->from_ssl); if (pending_in_ssl > 0) { *unprotected_bytes_size = 0; + GPR_ASSERT(*protected_output_frames_size <= INT_MAX); read_from_ssl = BIO_read(impl->from_ssl, protected_output_frames, - *protected_output_frames_size); + (int)*protected_output_frames_size); if (read_from_ssl < 0) { gpr_log(GPR_ERROR, "Could not read from BIO even though some data is pending"); @@ -684,8 +699,9 @@ static tsi_result ssl_protector_protect(tsi_frame_protector* self, result = do_ssl_write(impl->ssl, impl->buffer, impl->buffer_size); if (result != TSI_OK) return result; + GPR_ASSERT(*protected_output_frames_size <= INT_MAX); read_from_ssl = BIO_read(impl->from_ssl, protected_output_frames, - *protected_output_frames_size); + (int)*protected_output_frames_size); if (read_from_ssl < 0) { gpr_log(GPR_ERROR, "Could not read from BIO after SSL_write."); return TSI_INTERNAL_ERROR; @@ -715,8 +731,9 @@ static tsi_result ssl_protector_protect_flush( *still_pending_size = (size_t)pending; if (*still_pending_size == 0) return TSI_OK; + GPR_ASSERT(*protected_output_frames_size <= INT_MAX); read_from_ssl = BIO_read(impl->from_ssl, protected_output_frames, - *protected_output_frames_size); + (int)*protected_output_frames_size); if (read_from_ssl <= 0) { gpr_log(GPR_ERROR, "Could not read from BIO after SSL_write."); return TSI_INTERNAL_ERROR; @@ -751,8 +768,9 @@ static tsi_result ssl_protector_unprotect( *unprotected_bytes_size = output_bytes_size - output_bytes_offset; /* Then, try to write some data to ssl. */ + GPR_ASSERT(*protected_frames_bytes_size <= INT_MAX); written_into_ssl = BIO_write(impl->into_ssl, protected_frames_bytes, - *protected_frames_bytes_size); + (int)*protected_frames_bytes_size); if (written_into_ssl < 0) { gpr_log(GPR_ERROR, "Sending protected frame to ssl failed with %d", written_into_ssl); @@ -792,7 +810,8 @@ static tsi_result ssl_handshaker_get_bytes_to_send_to_peer(tsi_handshaker* self, *bytes_size > INT_MAX) { return TSI_INVALID_ARGUMENT; } - bytes_read_from_ssl = BIO_read(impl->from_ssl, bytes, *bytes_size); + GPR_ASSERT(*bytes_size <= INT_MAX); + bytes_read_from_ssl = BIO_read(impl->from_ssl, bytes, (int)*bytes_size); if (bytes_read_from_ssl < 0) { *bytes_size = 0; if (!BIO_should_retry(impl->from_ssl)) { @@ -822,7 +841,9 @@ static tsi_result ssl_handshaker_process_bytes_from_peer( if (bytes == NULL || bytes_size == 0 || *bytes_size > INT_MAX) { return TSI_INVALID_ARGUMENT; } - bytes_written_into_ssl_size = BIO_write(impl->into_ssl, bytes, *bytes_size); + GPR_ASSERT(*bytes_size <= INT_MAX); + bytes_written_into_ssl_size = + BIO_write(impl->into_ssl, bytes, (int)*bytes_size); if (bytes_written_into_ssl_size < 0) { gpr_log(GPR_ERROR, "Could not write to memory BIO."); impl->result = TSI_INTERNAL_ERROR; @@ -1044,9 +1065,9 @@ static tsi_result create_tsi_ssl_handshaker(SSL_CTX* ctx, int is_client, static int select_protocol_list(const unsigned char** out, unsigned char* outlen, const unsigned char* client_list, - unsigned int client_list_len, + size_t client_list_len, const unsigned char* server_list, - unsigned int server_list_len) { + size_t server_list_len) { const unsigned char* client_current = client_list; while ((unsigned int)(client_current - client_list) < client_list_len) { unsigned char client_current_len = *(client_current++); @@ -1219,7 +1240,8 @@ static int server_handshaker_factory_npn_advertised_callback( tsi_ssl_server_handshaker_factory* factory = (tsi_ssl_server_handshaker_factory*)arg; *out = factory->alpn_protocol_list; - *outlen = factory->alpn_protocol_list_length; + GPR_ASSERT(factory->alpn_protocol_list_length <= UINT_MAX); + *outlen = (unsigned int)factory->alpn_protocol_list_length; return SSL_TLSEXT_ERR_OK; } @@ -1277,8 +1299,10 @@ tsi_result tsi_create_ssl_client_handshaker_factory( break; } #if TSI_OPENSSL_ALPN_SUPPORT - if (SSL_CTX_set_alpn_protos(ssl_context, impl->alpn_protocol_list, - impl->alpn_protocol_list_length)) { + GPR_ASSERT(impl->alpn_protocol_list_length < UINT_MAX); + if (SSL_CTX_set_alpn_protos( + ssl_context, impl->alpn_protocol_list, + (unsigned int)impl->alpn_protocol_list_length)) { gpr_log(GPR_ERROR, "Could not set alpn protocol list to context."); result = TSI_INVALID_ARGUMENT; break; diff --git a/templates/Makefile.template b/templates/Makefile.template index 79640180f6..d6bcb54bac 100644 --- a/templates/Makefile.template +++ b/templates/Makefile.template @@ -247,6 +247,10 @@ 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) + # 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. # 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 @@ -262,6 +266,9 @@ endif CFLAGS += -std=c89 -pedantic -Wsign-conversion + ifeq ($(HAS_SHORTEN_64_TO_32),true) + CFLAGS += -Wshorten-64-to-32 + endif ifeq ($(HAS_CXX11),true) CXXFLAGS += -std=c++11 else diff --git a/test/build/empty.c b/test/build/empty.c new file mode 100644 index 0000000000..58e4698aee --- /dev/null +++ b/test/build/empty.c @@ -0,0 +1,34 @@ +/* + * + * Copyright 2015, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +int main(void) {} diff --git a/test/core/compression/message_compress_test.c b/test/core/compression/message_compress_test.c index 495841c79f..98da6a1eaa 100644 --- a/test/core/compression/message_compress_test.c +++ b/test/core/compression/message_compress_test.c @@ -149,7 +149,7 @@ static gpr_slice create_test_value(test_value id) { static void test_bad_data(void) { gpr_slice_buffer input; gpr_slice_buffer output; - int i; + grpc_compression_algorithm i; gpr_slice_buffer_init(&input); gpr_slice_buffer_init(&output); diff --git a/test/core/fling/server.c b/test/core/fling/server.c index 64f9573084..5aace03520 100644 --- a/test/core/fling/server.c +++ b/test/core/fling/server.c @@ -197,7 +197,7 @@ int main(int argc, char **argv) { grpc_test_init(1, fake_argv); grpc_init(); - srand(clock()); + srand((unsigned)clock()); cl = gpr_cmdline_create("fling server"); gpr_cmdline_add_string(cl, "bind", "Bind host:port", &addr); diff --git a/test/core/iomgr/fd_posix_test.c b/test/core/iomgr/fd_posix_test.c index 8bba87d61f..af66ef0997 100644 --- a/test/core/iomgr/fd_posix_test.c +++ b/test/core/iomgr/fd_posix_test.c @@ -419,7 +419,7 @@ static void test_grpc_fd_change(void) { int flags; int sv[2]; char data; - int result; + ssize_t result; grpc_iomgr_closure first_closure; grpc_iomgr_closure second_closure; diff --git a/test/core/iomgr/udp_server_test.c b/test/core/iomgr/udp_server_test.c index c91752b937..8c964246c7 100644 --- a/test/core/iomgr/udp_server_test.c +++ b/test/core/iomgr/udp_server_test.c @@ -53,7 +53,7 @@ static void on_connect(void *arg, grpc_endpoint *udp) {} static void on_read(int fd, grpc_udp_server_cb new_transport_cb, void *cb_arg) { char read_buffer[512]; - int byte_count; + ssize_t byte_count; gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset)); byte_count = recv(fd, read_buffer, sizeof(read_buffer), 0); diff --git a/test/core/support/murmur_hash_test.c b/test/core/support/murmur_hash_test.c index 1e5279f462..1762486776 100644 --- a/test/core/support/murmur_hash_test.c +++ b/test/core/support/murmur_hash_test.c @@ -57,8 +57,8 @@ static void verification_test(hash_func hash, gpr_uint32 expected) { the seed */ for (i = 0; i < 256; i++) { - key[i] = (uint8_t)i; - hashes[i] = hash(key, i, 256u - i); + key[i] = (gpr_uint8)i; + hashes[i] = hash(key, i, (gpr_uint32)(256u - i)); } /* Then hash the result array */ diff --git a/test/core/support/stack_lockfree_test.c b/test/core/support/stack_lockfree_test.c index 4a2a0532d8..0f49e6fa52 100644 --- a/test/core/support/stack_lockfree_test.c +++ b/test/core/support/stack_lockfree_test.c @@ -62,7 +62,7 @@ static void test_serial_sized(size_t size) { /* Now add repeatedly more items and check them */ for (i = 1; i < size; i *= 2) { for (j = 0; j <= i; j++) { - GPR_ASSERT(gpr_stack_lockfree_push(stack, j) == (j == 0)); + GPR_ASSERT(gpr_stack_lockfree_push(stack, (int)j) == (j == 0)); } for (j = 0; j <= i; j++) { GPR_ASSERT(gpr_stack_lockfree_pop(stack) == (int)(i - j)); @@ -118,7 +118,7 @@ static void test_mt_sized(size_t size, int nth) { stack = gpr_stack_lockfree_create(size); for (i = 0; i < nth; i++) { args[i].stack = stack; - args[i].stack_size = size; + args[i].stack_size = (int)size; args[i].nthreads = nth; args[i].rank = i; args[i].sum = 0; @@ -137,7 +137,8 @@ static void test_mt_sized(size_t size, int nth) { } static void test_mt() { - size_t size, nth; + size_t size; + int nth; for (nth = 1; nth < MAX_THREADS; nth++) { for (size = 128; size < MAX_STACK_SIZE; size *= 2) { test_mt_sized(size, nth); diff --git a/test/core/transport/chttp2/hpack_table_test.c b/test/core/transport/chttp2/hpack_table_test.c index ec0a569371..aa3e273a6c 100644 --- a/test/core/transport/chttp2/hpack_table_test.c +++ b/test/core/transport/chttp2/hpack_table_test.c @@ -49,7 +49,7 @@ static void assert_str(const grpc_chttp2_hptbl *tbl, grpc_mdstr *mdstr, GPR_ASSERT(gpr_slice_str_cmp(mdstr->slice, str) == 0); } -static void assert_index(const grpc_chttp2_hptbl *tbl, size_t idx, +static void assert_index(const grpc_chttp2_hptbl *tbl, gpr_uint32 idx, const char *key, const char *value) { grpc_mdelem *md = grpc_chttp2_hptbl_lookup(tbl, idx); assert_str(tbl, md->key, key); diff --git a/test/core/transport/chttp2/stream_encoder_test.c b/test/core/transport/chttp2/stream_encoder_test.c index 4bb503b4e9..a723b90084 100644 --- a/test/core/transport/chttp2/stream_encoder_test.c +++ b/test/core/transport/chttp2/stream_encoder_test.c @@ -75,8 +75,8 @@ static void verify_sopb(size_t window_available, int eof, gpr_slice_buffer_init(&output); grpc_sopb_init(&encops); GPR_ASSERT(expect_window_used == - grpc_chttp2_preencode(g_sopb.ops, &g_sopb.nops, window_available, - &encops)); + grpc_chttp2_preencode(g_sopb.ops, &g_sopb.nops, + (gpr_uint32)window_available, &encops)); grpc_chttp2_encode(encops.ops, encops.nops, eof, 0xdeadbeef, &g_compressor, &output); encops.nops = 0; diff --git a/test/core/transport/chttp2/stream_map_test.c b/test/core/transport/chttp2/stream_map_test.c index 72aaafd18d..81fb80f84f 100644 --- a/test/core/transport/chttp2/stream_map_test.c +++ b/test/core/transport/chttp2/stream_map_test.c @@ -82,9 +82,9 @@ static void test_double_deletion(void) { } /* test add & lookup */ -static void test_basic_add_find(size_t n) { +static void test_basic_add_find(gpr_uint32 n) { grpc_chttp2_stream_map map; - size_t i; + gpr_uint32 i; size_t got; LOG_TEST("test_basic_add_find"); @@ -107,15 +107,15 @@ static void test_basic_add_find(size_t n) { /* verify that for_each gets the right values during test_delete_evens_XXX */ static void verify_for_each(void *user_data, gpr_uint32 stream_id, void *ptr) { - size_t *for_each_check = user_data; + gpr_uint32 *for_each_check = user_data; GPR_ASSERT(ptr); GPR_ASSERT(*for_each_check == stream_id); *for_each_check += 2; } -static void check_delete_evens(grpc_chttp2_stream_map *map, size_t n) { - size_t for_each_check = 1; - size_t i; +static void check_delete_evens(grpc_chttp2_stream_map *map, gpr_uint32 n) { + gpr_uint32 for_each_check = 1; + gpr_uint32 i; size_t got; GPR_ASSERT(NULL == grpc_chttp2_stream_map_find(map, 0)); @@ -139,9 +139,9 @@ static void check_delete_evens(grpc_chttp2_stream_map *map, size_t n) { /* add a bunch of keys, delete the even ones, and make sure the map is consistent */ -static void test_delete_evens_sweep(size_t n) { +static void test_delete_evens_sweep(gpr_uint32 n) { grpc_chttp2_stream_map map; - size_t i; + gpr_uint32 i; LOG_TEST("test_delete_evens_sweep"); gpr_log(GPR_INFO, "n = %d", n); @@ -152,7 +152,8 @@ static void test_delete_evens_sweep(size_t n) { } for (i = 1; i <= n; i++) { if ((i & 1) == 0) { - GPR_ASSERT((void *)i == grpc_chttp2_stream_map_delete(&map, i)); + GPR_ASSERT((void *)(gpr_uintptr)i == + grpc_chttp2_stream_map_delete(&map, i)); } } check_delete_evens(&map, n); @@ -161,9 +162,9 @@ static void test_delete_evens_sweep(size_t n) { /* add a bunch of keys, delete the even ones immediately, and make sure the map is consistent */ -static void test_delete_evens_incremental(size_t n) { +static void test_delete_evens_incremental(gpr_uint32 n) { grpc_chttp2_stream_map map; - size_t i; + gpr_uint32 i; LOG_TEST("test_delete_evens_incremental"); gpr_log(GPR_INFO, "n = %d", n); @@ -181,10 +182,10 @@ static void test_delete_evens_incremental(size_t n) { /* add a bunch of keys, delete old ones after some time, ensure the backing array does not grow */ -static void test_periodic_compaction(size_t n) { +static void test_periodic_compaction(gpr_uint32 n) { grpc_chttp2_stream_map map; - size_t i; - size_t del; + gpr_uint32 i; + gpr_uint32 del; LOG_TEST("test_periodic_compaction"); gpr_log(GPR_INFO, "n = %d", n); @@ -192,10 +193,11 @@ static void test_periodic_compaction(size_t n) { grpc_chttp2_stream_map_init(&map, 16); GPR_ASSERT(map.capacity == 16); for (i = 1; i <= n; i++) { - grpc_chttp2_stream_map_add(&map, i, (void *)i); + grpc_chttp2_stream_map_add(&map, i, (void *)(gpr_uintptr)i); if (i > 8) { del = i - 8; - GPR_ASSERT((void *)del == grpc_chttp2_stream_map_delete(&map, del)); + GPR_ASSERT((void *)(gpr_uintptr)del == + grpc_chttp2_stream_map_delete(&map, del)); } } GPR_ASSERT(map.capacity == 16); @@ -203,9 +205,9 @@ static void test_periodic_compaction(size_t n) { } int main(int argc, char **argv) { - size_t n = 1; - size_t prev = 1; - size_t tmp; + gpr_uint32 n = 1; + gpr_uint32 prev = 1; + gpr_uint32 tmp; grpc_test_init(argc, argv); diff --git a/tools/codegen/core/gen_hpack_tables.c b/tools/codegen/core/gen_hpack_tables.c index 555f1e71c5..dec0e2f3fe 100644 --- a/tools/codegen/core/gen_hpack_tables.c +++ b/tools/codegen/core/gen_hpack_tables.c @@ -127,7 +127,9 @@ static void generate_first_byte_lut(void) { /* represents a set of symbols as an array of booleans indicating inclusion */ typedef struct { char included[GRPC_CHTTP2_NUM_HUFFSYMS]; } symset; /* represents a lookup table indexed by a nibble */ -typedef struct { int values[16]; } nibblelut; +typedef struct { unsigned values[16]; } nibblelut; + +#define NOT_SET (~(unsigned)0) /* returns a symset that includes all possible symbols */ static symset symset_all(void) { @@ -148,7 +150,7 @@ static nibblelut nibblelut_empty(void) { nibblelut x; int i; for (i = 0; i < 16; i++) { - x.values[i] = -1; + x.values[i] = NOT_SET; } return x; } @@ -168,7 +170,7 @@ static int nsyms(symset s) { /* global table of discovered huffman decoding states */ static struct { /* the bit offset that this state starts at */ - int bitofs; + unsigned bitofs; /* the set of symbols that this state started with */ symset syms; @@ -177,13 +179,13 @@ static struct { /* lookup table for what to emit */ nibblelut emit; } huffstates[MAXHUFFSTATES]; -static int nhuffstates = 0; +static unsigned nhuffstates = 0; /* given a number of decoded bits and a set of symbols that are live, return the index into the decoder table for this state. set isnew to 1 if this state was previously undiscovered */ -static int state_index(int bitofs, symset syms, int *isnew) { - int i; +static unsigned state_index(unsigned bitofs, symset syms, unsigned *isnew) { + unsigned i; for (i = 0; i < nhuffstates; i++) { if (huffstates[i].bitofs != bitofs) continue; if (0 != memcmp(huffstates[i].syms.included, syms.included, @@ -211,24 +213,24 @@ static int state_index(int bitofs, symset syms, int *isnew) { emit - the symbol to emit on this nibble (or -1 if no symbol has been found) syms - the set of symbols that could be matched */ -static void build_dec_tbl(int state, int nibble, int nibbits, unsigned bitofs, - int emit, symset syms) { - int i; +static void build_dec_tbl(unsigned state, unsigned nibble, int nibbits, + unsigned bitofs, unsigned emit, symset syms) { + unsigned i; unsigned bit; /* If we have four bits in the nibble we're looking at, then we can fill in a slot in the lookup tables. */ if (nibbits == 4) { - int isnew; + unsigned isnew; /* Find the state that we are in: this may be a new state, in which case we recurse to fill it in, or we may have already seen this state, in which case the recursion terminates */ - int st = state_index(bitofs, syms, &isnew); - GPR_ASSERT(huffstates[state].next.values[nibble] == -1); + unsigned st = state_index(bitofs, syms, &isnew); + GPR_ASSERT(huffstates[state].next.values[nibble] == NOT_SET); huffstates[state].next.values[nibble] = st; huffstates[state].emit.values[nibble] = emit; if (isnew) { - build_dec_tbl(st, 0, 0, bitofs, -1, syms); + build_dec_tbl(st, 0, 0, bitofs, NOT_SET, syms); } return; } @@ -290,8 +292,9 @@ static void dump_ctbl(const char *name) { } static void generate_huff_tables(void) { - int i; - build_dec_tbl(state_index(0, symset_all(), &i), 0, 0, 0, -1, symset_all()); + unsigned i; + build_dec_tbl(state_index(0, symset_all(), &i), 0, 0, 0, NOT_SET, + symset_all()); nctbl = 0; printf("static const gpr_uint8 next_tbl[%d] = {", nhuffstates); -- cgit v1.2.3 From 2ed498151da3b68107312b6397dbff4b4f60e475 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Thu, 10 Sep 2015 14:54:26 -0700 Subject: Fix typo --- src/core/transport/chttp2/parsing.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/core/transport/chttp2/parsing.c') diff --git a/src/core/transport/chttp2/parsing.c b/src/core/transport/chttp2/parsing.c index a29987a05a..5d3dfe2286 100644 --- a/src/core/transport/chttp2/parsing.c +++ b/src/core/transport/chttp2/parsing.c @@ -194,8 +194,9 @@ void grpc_chttp2_publish_reads( GRPC_CHTTP2_FLOWCTL_TRACE_STREAM( "parsed", transport_parsing, stream_parsing, outgoing_window_update, -(gpr_int64)stream_parsing->outgoing_window_update); + GPR_ASSERT(stream_parsing->outgoing_window_update <= GPR_UINT32_MAX); stream_global->outgoing_window += - (gpr_uint32)stream_global->outgoing_window; + (gpr_uint32)stream_parsing->outgoing_window_update; stream_parsing->outgoing_window_update = 0; is_zero = stream_global->outgoing_window <= 0; if (was_zero && !is_zero) { -- cgit v1.2.3 From 6a6b36c50300bcc33d761598591c4d1bd4f1f6aa Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Thu, 10 Sep 2015 16:00:22 -0700 Subject: Enable -Wconversion --- Makefile | 9 +--- src/core/channel/compress_filter.c | 5 ++- .../client_config/resolvers/sockaddr_resolver.c | 4 +- src/core/iomgr/alarm.c | 6 +-- .../iomgr/pollset_multipoller_with_poll_posix.c | 4 +- src/core/iomgr/pollset_posix.c | 2 +- src/core/iomgr/sockaddr_utils.c | 12 ++++-- src/core/surface/call.c | 11 ++--- src/core/transport/chttp2/bin_encoder.c | 23 +++++----- src/core/transport/chttp2/frame_data.c | 3 +- src/core/transport/chttp2/frame_goaway.c | 25 +++++------ src/core/transport/chttp2/frame_rst_stream.c | 16 +++---- src/core/transport/chttp2/frame_settings.c | 22 +++++----- src/core/transport/chttp2/frame_window_update.c | 16 +++---- src/core/transport/chttp2/hpack_parser.c | 18 ++++---- src/core/transport/chttp2/hpack_table.c | 31 ++++++++------ src/core/transport/chttp2/internal.h | 4 +- src/core/transport/chttp2/parsing.c | 8 ++-- src/core/transport/chttp2/stream_encoder.c | 49 ++++++++++++---------- src/core/transport/chttp2/varint.h | 2 +- src/core/transport/chttp2_transport.c | 49 +++++++++++----------- src/core/transport/metadata.c | 4 +- templates/Makefile.template | 9 +--- test/core/fling/client.c | 2 +- test/core/iomgr/endpoint_tests.c | 6 +-- test/core/iomgr/fd_posix_test.c | 3 +- test/core/iomgr/tcp_posix_test.c | 10 ++--- test/core/iomgr/udp_server_test.c | 2 +- test/core/json/json_rewrite.c | 6 ++- test/core/json/json_rewrite_test.c | 3 +- test/core/support/slice_test.c | 6 +-- test/core/transport/chttp2/stream_encoder_test.c | 8 ++-- test/core/util/parse_hexstring.c | 4 +- test/core/util/port_posix.c | 2 +- test/core/util/reconnect_server.c | 2 +- test/core/util/test_config.h | 18 ++++---- tools/codegen/core/gen_hpack_tables.c | 8 ++-- tools/codegen/core/gen_legal_metadata_characters.c | 2 +- 38 files changed, 216 insertions(+), 198 deletions(-) (limited to 'src/core/transport/chttp2/parsing.c') diff --git a/Makefile b/Makefile index 21f3011a6e..b705129a7b 100644 --- a/Makefile +++ b/Makefile @@ -231,10 +231,6 @@ endif 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) -# 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. # 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 @@ -249,10 +245,7 @@ ifdef EXTRA_DEFINES DEFINES += $(EXTRA_DEFINES) endif -CFLAGS += -std=c89 -pedantic -Wsign-conversion -ifeq ($(HAS_SHORTEN_64_TO_32),true) -CFLAGS += -Wshorten-64-to-32 -endif +CFLAGS += -std=c89 -pedantic -Wsign-conversion -Wconversion ifeq ($(HAS_CXX11),true) CXXFLAGS += -std=c++11 else diff --git a/src/core/channel/compress_filter.c b/src/core/channel/compress_filter.c index 8e06094257..c47b91bc58 100644 --- a/src/core/channel/compress_filter.c +++ b/src/core/channel/compress_filter.c @@ -230,7 +230,10 @@ static void process_send_ops(grpc_call_element *elem, GPR_ASSERT(calld->remaining_slice_bytes > 0); /* Increase input ref count, gpr_slice_buffer_add takes ownership. */ 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) { did_compress = compress_send_sb(calld->compression_algorithm, &calld->slices); diff --git a/src/core/client_config/resolvers/sockaddr_resolver.c b/src/core/client_config/resolvers/sockaddr_resolver.c index 4a3c14545a..85b1bf2849 100644 --- a/src/core/client_config/resolvers/sockaddr_resolver.c +++ b/src/core/client_config/resolvers/sockaddr_resolver.c @@ -218,7 +218,7 @@ static int parse_ipv4(grpc_uri *uri, struct sockaddr_storage *addr, gpr_log(GPR_ERROR, "invalid ipv4 port: '%s'", port); goto done; } - in->sin_port = htons(port_num); + in->sin_port = htons((gpr_uint16)port_num); } else { gpr_log(GPR_ERROR, "no port given for ipv4 scheme"); 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); goto done; } - in6->sin6_port = htons(port_num); + in6->sin6_port = htons((gpr_uint16)port_num); } else { gpr_log(GPR_ERROR, "no port given for ipv6 scheme"); goto done; diff --git a/src/core/iomgr/alarm.c b/src/core/iomgr/alarm.c index 515b96ffc1..7b67fe3b1d 100644 --- a/src/core/iomgr/alarm.c +++ b/src/core/iomgr/alarm.c @@ -123,13 +123,13 @@ static size_t shard_idx(const grpc_alarm *info) { } 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) { gpr_timespec ts; - ts.tv_sec = d; - ts.tv_nsec = 1e9 * (d - ts.tv_sec); + ts.tv_sec = (time_t)d; + ts.tv_nsec = (int)(1e9 * (d - (double)ts.tv_sec)); ts.clock_type = GPR_TIMESPAN; return ts; } diff --git a/src/core/iomgr/pollset_multipoller_with_poll_posix.c b/src/core/iomgr/pollset_multipoller_with_poll_posix.c index 30ee6e24db..f1bc60ba4e 100644 --- a/src/core/iomgr/pollset_multipoller_with_poll_posix.c +++ b/src/core/iomgr/pollset_multipoller_with_poll_posix.c @@ -140,8 +140,8 @@ static void multipoll_with_poll_pollset_maybe_work( gpr_mu_unlock(&pollset->mu); for (i = 1; i < pfd_count; i++) { - pfds[i].events = grpc_fd_begin_poll(watchers[i].fd, pollset, POLLIN, - POLLOUT, &watchers[i]); + pfds[i].events = (short)grpc_fd_begin_poll(watchers[i].fd, pollset, POLLIN, + POLLOUT, &watchers[i]); } r = grpc_poll_function(pfds, pfd_count, timeout); diff --git a/src/core/iomgr/pollset_posix.c b/src/core/iomgr/pollset_posix.c index 93aa3ad662..dec2f5490f 100644 --- a/src/core/iomgr/pollset_posix.c +++ b/src/core/iomgr/pollset_posix.c @@ -443,7 +443,7 @@ static void basic_pollset_maybe_work(grpc_pollset *pollset, pfd[1].revents = 0; gpr_mu_unlock(&pollset->mu); 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) { nfds++; } diff --git a/src/core/iomgr/sockaddr_utils.c b/src/core/iomgr/sockaddr_utils.c index efdc480365..0e4bf24549 100644 --- a/src/core/iomgr/sockaddr_utils.c +++ b/src/core/iomgr/sockaddr_utils.c @@ -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) { + GPR_ASSERT(port >= 0 && port < 65536); memset(wild_out, 0, sizeof(*wild_out)); 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) { + GPR_ASSERT(port >= 0 && port < 65536); memset(wild_out, 0, sizeof(*wild_out)); 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, @@ -215,10 +217,12 @@ int grpc_sockaddr_get_port(const struct sockaddr *addr) { int grpc_sockaddr_set_port(const struct sockaddr *addr, int port) { switch (addr->sa_family) { 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; 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; default: gpr_log(GPR_ERROR, "Unknown socket family %d in grpc_sockaddr_set_port", diff --git a/src/core/surface/call.c b/src/core/surface/call.c index c96df77a98..16a7d2ec35 100644 --- a/src/core/surface/call.c +++ b/src/core/surface/call.c @@ -421,7 +421,7 @@ static grpc_cq_completion *allocate_completion(grpc_call *call) { if (call->allocated_completions & (1u << i)) { continue; } - call->allocated_completions |= 1u << i; + call->allocated_completions |= (gpr_uint8)(1u << i); gpr_mu_unlock(&call->completion_mu); 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) { grpc_call *c = call; 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); 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; /* ioreq is live: we need to do something */ master = &call->masters[master_set]; - master->complete_mask |= 1u << op; + master->complete_mask |= (gpr_uint16)(1u << op); if (!success) { 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, void *user_data) { size_t i; - gpr_uint32 have_ops = 0; + gpr_uint16 have_ops = 0; grpc_ioreq_op op; reqinfo_master *master; 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)); } } - have_ops |= 1u << op; + have_ops |= (gpr_uint16)(1u << op); call->request_data[op] = data; call->request_flags[op] = reqs[i].flags; diff --git a/src/core/transport/chttp2/bin_encoder.c b/src/core/transport/chttp2/bin_encoder.c index b87d4de04b..e21d800083 100644 --- a/src/core/transport/chttp2/bin_encoder.c +++ b/src/core/transport/chttp2/bin_encoder.c @@ -128,12 +128,13 @@ gpr_slice grpc_chttp2_huffman_compress(gpr_slice input) { while (temp_length > 8) { temp_length -= 8; - *out++ = temp >> temp_length; + *out++ = (gpr_uint8)(temp >> 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)); @@ -150,7 +151,7 @@ typedef struct { static void enc_flush_some(huff_out *out) { while (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 */ for (i = 0; i < input_triplets; i++) { - enc_add2(&out, in[0] >> 2, ((in[0] & 0x3) << 4) | (in[1] >> 4)); - enc_add2(&out, ((in[1] & 0xf) << 2) | (in[2] >> 6), in[2] & 0x3f); + enc_add2(&out, in[0] >> 2, (gpr_uint8)((in[0] & 0x3) << 4) | (in[1] >> 4)); + enc_add2(&out, (gpr_uint8)((in[1] & 0xf) << 2) | (in[2] >> 6), + (gpr_uint8)(in[2] & 0x3f)); in += 3; } @@ -199,19 +201,20 @@ gpr_slice grpc_chttp2_base64_encode_and_huffman_compress(gpr_slice input) { case 0: break; 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; break; case 2: - enc_add2(&out, in[0] >> 2, ((in[0] & 0x3) << 4) | (in[1] >> 4)); - enc_add1(&out, (in[1] & 0xf) << 2); + enc_add2(&out, in[0] >> 2, + (gpr_uint8)((in[0] & 0x3) << 4) | (gpr_uint8)(in[1] >> 4)); + enc_add1(&out, (gpr_uint8)((in[1] & 0xf) << 2)); in += 2; break; } if (out.temp_length) { - *out.out++ = - (out.temp << (8u - out.temp_length)) | (0xffu >> out.temp_length); + *out.out++ = (gpr_uint8)(out.temp << (8u - out.temp_length)) | + (gpr_uint8)(0xffu >> out.temp_length); } GPR_ASSERT(out.out <= GPR_SLICE_END_PTR(output)); diff --git a/src/core/transport/chttp2/frame_data.c b/src/core/transport/chttp2/frame_data.c index 29d19b4e94..403358016d 100644 --- a/src/core/transport/chttp2/frame_data.c +++ b/src/core/transport/chttp2/frame_data.c @@ -161,7 +161,8 @@ grpc_chttp2_parse_error grpc_chttp2_data_parser_parse( grpc_sopb_add_slice( &p->incoming_sopb, 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; } } diff --git a/src/core/transport/chttp2/frame_goaway.c b/src/core/transport/chttp2/frame_goaway.c index 1a6d80da58..09d4da234c 100644 --- a/src/core/transport/chttp2/frame_goaway.c +++ b/src/core/transport/chttp2/frame_goaway.c @@ -137,7 +137,8 @@ grpc_chttp2_parse_error grpc_chttp2_goaway_parser_parse( /* fallthrough */ case GRPC_CHTTP2_GOAWAY_DEBUG: 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; if (is_last) { 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 header: length */ - *p++ = frame_length >> 16; - *p++ = frame_length >> 8; - *p++ = frame_length; + *p++ = (gpr_uint8)(frame_length >> 16); + *p++ = (gpr_uint8)(frame_length >> 8); + *p++ = (gpr_uint8)(frame_length); /* frame header: type */ *p++ = GRPC_CHTTP2_FRAME_GOAWAY; /* 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; /* payload: last stream id */ - *p++ = last_stream_id >> 24; - *p++ = last_stream_id >> 16; - *p++ = last_stream_id >> 8; - *p++ = last_stream_id; + *p++ = (gpr_uint8)(last_stream_id >> 24); + *p++ = (gpr_uint8)(last_stream_id >> 16); + *p++ = (gpr_uint8)(last_stream_id >> 8); + *p++ = (gpr_uint8)(last_stream_id); /* payload: error code */ - *p++ = error_code >> 24; - *p++ = error_code >> 16; - *p++ = error_code >> 8; - *p++ = error_code; + *p++ = (gpr_uint8)(error_code >> 24); + *p++ = (gpr_uint8)(error_code >> 16); + *p++ = (gpr_uint8)(error_code >> 8); + *p++ = (gpr_uint8)(error_code); GPR_ASSERT(p == GPR_SLICE_END_PTR(header)); gpr_slice_buffer_add(slice_buffer, header); gpr_slice_buffer_add(slice_buffer, debug_data); diff --git a/src/core/transport/chttp2/frame_rst_stream.c b/src/core/transport/chttp2/frame_rst_stream.c index a878d936c1..67da245239 100644 --- a/src/core/transport/chttp2/frame_rst_stream.c +++ b/src/core/transport/chttp2/frame_rst_stream.c @@ -47,14 +47,14 @@ gpr_slice grpc_chttp2_rst_stream_create(gpr_uint32 id, gpr_uint32 code) { *p++ = 4; *p++ = GRPC_CHTTP2_FRAME_RST_STREAM; *p++ = 0; - *p++ = id >> 24; - *p++ = id >> 16; - *p++ = id >> 8; - *p++ = id; - *p++ = code >> 24; - *p++ = code >> 16; - *p++ = code >> 8; - *p++ = code; + *p++ = (gpr_uint8)(id >> 24); + *p++ = (gpr_uint8)(id >> 16); + *p++ = (gpr_uint8)(id >> 8); + *p++ = (gpr_uint8)(id); + *p++ = (gpr_uint8)(code >> 24); + *p++ = (gpr_uint8)(code >> 16); + *p++ = (gpr_uint8)(code >> 8); + *p++ = (gpr_uint8)(code); return slice; } diff --git a/src/core/transport/chttp2/frame_settings.c b/src/core/transport/chttp2/frame_settings.c index f70776bf4c..54d3694a5c 100644 --- a/src/core/transport/chttp2/frame_settings.c +++ b/src/core/transport/chttp2/frame_settings.c @@ -61,9 +61,9 @@ const grpc_chttp2_setting_parameters static gpr_uint8 *fill_header(gpr_uint8 *out, gpr_uint32 length, gpr_uint8 flags) { - *out++ = length >> 16; - *out++ = length >> 8; - *out++ = length; + *out++ = (gpr_uint8)(length >> 16); + *out++ = (gpr_uint8)(length >> 8); + *out++ = (gpr_uint8)(length); *out++ = GRPC_CHTTP2_FRAME_SETTINGS; *out++ = flags; *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++) { if (new[i] != old[i] || (force_mask & (1u << i)) != 0) { GPR_ASSERT(i); - *p++ = i >> 8; - *p++ = i; - *p++ = new[i] >> 24; - *p++ = new[i] >> 16; - *p++ = new[i] >> 8; - *p++ = new[i]; + *p++ = (gpr_uint8)(i >> 8); + *p++ = (gpr_uint8)(i); + *p++ = (gpr_uint8)(new[i] >> 24); + *p++ = (gpr_uint8)(new[i] >> 16); + *p++ = (gpr_uint8)(new[i] >> 8); + *p++ = (gpr_uint8)(new[i]); old[i] = new[i]; } } @@ -162,7 +162,7 @@ grpc_chttp2_parse_error grpc_chttp2_settings_parser_parse( } return GRPC_CHTTP2_PARSE_OK; } - parser->id = ((gpr_uint16)*cur) << 8; + parser->id = (gpr_uint16)(((gpr_uint16)*cur) << 8); cur++; /* fallthrough */ case GRPC_CHTTP2_SPS_ID1: @@ -170,7 +170,7 @@ grpc_chttp2_parse_error grpc_chttp2_settings_parser_parse( parser->state = GRPC_CHTTP2_SPS_ID1; return GRPC_CHTTP2_PARSE_OK; } - parser->id |= (*cur); + parser->id = (gpr_uint16)(parser->id | (*cur)); cur++; /* fallthrough */ case GRPC_CHTTP2_SPS_VAL0: diff --git a/src/core/transport/chttp2/frame_window_update.c b/src/core/transport/chttp2/frame_window_update.c index d624298ad2..ea13969e8c 100644 --- a/src/core/transport/chttp2/frame_window_update.c +++ b/src/core/transport/chttp2/frame_window_update.c @@ -48,14 +48,14 @@ gpr_slice grpc_chttp2_window_update_create(gpr_uint32 id, *p++ = 4; *p++ = GRPC_CHTTP2_FRAME_WINDOW_UPDATE; *p++ = 0; - *p++ = id >> 24; - *p++ = id >> 16; - *p++ = id >> 8; - *p++ = id; - *p++ = window_update >> 24; - *p++ = window_update >> 16; - *p++ = window_update >> 8; - *p++ = window_update; + *p++ = (gpr_uint8)(id >> 24); + *p++ = (gpr_uint8)(id >> 16); + *p++ = (gpr_uint8)(id >> 8); + *p++ = (gpr_uint8)(id); + *p++ = (gpr_uint8)(window_update >> 24); + *p++ = (gpr_uint8)(window_update >> 16); + *p++ = (gpr_uint8)(window_update >> 8); + *p++ = (gpr_uint8)(window_update); return slice; } diff --git a/src/core/transport/chttp2/hpack_parser.c b/src/core/transport/chttp2/hpack_parser.c index 93a452f1fd..9c40e8a4e6 100644 --- a/src/core/transport/chttp2/hpack_parser.c +++ b/src/core/transport/chttp2/hpack_parser.c @@ -1090,7 +1090,8 @@ static void append_bytes(grpc_chttp2_hpack_parser_string *str, str->str = gpr_realloc(str->str, str->capacity); } 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, @@ -1158,9 +1159,9 @@ static int append_string(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur, goto b64_byte3; p->base64_buffer |= bits; bits = p->base64_buffer; - decoded[0] = bits >> 16; - decoded[1] = bits >> 8; - decoded[2] = bits; + decoded[0] = (gpr_uint8)(bits >> 16); + decoded[1] = (gpr_uint8)(bits >> 8); + decoded[2] = (gpr_uint8)(bits); append_bytes(str, decoded, 3); goto b64_byte0; } @@ -1190,7 +1191,7 @@ static int finish_str(grpc_chttp2_hpack_parser *p) { bits & 0xffff); return 0; } - decoded[0] = bits >> 16; + decoded[0] = (gpr_uint8)(bits >> 16); append_bytes(str, decoded, 1); break; case B64_BYTE3: @@ -1200,8 +1201,8 @@ static int finish_str(grpc_chttp2_hpack_parser *p) { bits & 0xff); return 0; } - decoded[0] = bits >> 16; - decoded[1] = bits >> 8; + decoded[0] = (gpr_uint8)(bits >> 16); + decoded[1] = (gpr_uint8)(bits >> 8); append_bytes(str, decoded, 2); break; } @@ -1256,7 +1257,8 @@ static int parse_string(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur, parse_next(p, cur + remaining, end); } else { 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; return 1; } diff --git a/src/core/transport/chttp2/hpack_table.c b/src/core/transport/chttp2/hpack_table.c index 3aeb4dae94..e18778ab0b 100644 --- a/src/core/transport/chttp2/hpack_table.c +++ b/src/core/transport/chttp2/hpack_table.c @@ -150,19 +150,22 @@ grpc_mdelem *grpc_chttp2_hptbl_lookup(const grpc_chttp2_hptbl *tbl, /* Evict one element from the table */ static void evict1(grpc_chttp2_hptbl *tbl) { grpc_mdelem *first_ent = tbl->ents[tbl->first_ent]; - tbl->mem_used -= GPR_SLICE_LENGTH(first_ent->key->slice) + - GPR_SLICE_LENGTH(first_ent->value->slice) + - GRPC_CHTTP2_HPACK_ENTRY_OVERHEAD; - tbl->first_ent = (tbl->first_ent + 1) % GRPC_CHTTP2_MAX_TABLE_COUNT; + size_t elem_bytes = GPR_SLICE_LENGTH(first_ent->key->slice) + + GPR_SLICE_LENGTH(first_ent->value->slice) + + GRPC_CHTTP2_HPACK_ENTRY_OVERHEAD; + 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--; GRPC_MDELEM_UNREF(first_ent); } void grpc_chttp2_hptbl_add(grpc_chttp2_hptbl *tbl, grpc_mdelem *md) { /* determine how many bytes of buffer this entry represents */ - gpr_uint16 elem_bytes = GPR_SLICE_LENGTH(md->key->slice) + - GPR_SLICE_LENGTH(md->value->slice) + - GRPC_CHTTP2_HPACK_ENTRY_OVERHEAD; + size_t elem_bytes = GPR_SLICE_LENGTH(md->key->slice) + + GPR_SLICE_LENGTH(md->value->slice) + + GRPC_CHTTP2_HPACK_ENTRY_OVERHEAD; /* we can't add elements bigger than the max table size */ 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 */ - while (elem_bytes > tbl->max_bytes - tbl->mem_used) { + while (elem_bytes > (size_t)tbl->max_bytes - tbl->mem_used) { evict1(tbl); } @@ -190,28 +193,30 @@ void grpc_chttp2_hptbl_add(grpc_chttp2_hptbl *tbl, grpc_mdelem *md) { tbl->ents[tbl->last_ent] = md; /* 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->mem_used += elem_bytes; + tbl->mem_used = (gpr_uint16)(tbl->mem_used + elem_bytes); } grpc_chttp2_hptbl_find_result grpc_chttp2_hptbl_find( const grpc_chttp2_hptbl *tbl, grpc_mdelem *md) { grpc_chttp2_hptbl_find_result r = {0, 0}; - int i; + gpr_uint16 i; /* See if the string is in the static table */ for (i = 0; i < GRPC_CHTTP2_LAST_STATIC_ENTRY; i++) { grpc_mdelem *ent = tbl->static_ents[i]; if (md->key != ent->key) continue; - r.index = i + 1; + r.index = (gpr_uint16)(i + 1); r.has_value = md->value == ent->value; if (r.has_value) return r; } /* Scan the dynamic table */ 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 = tbl->ents[(tbl->first_ent + i) % GRPC_CHTTP2_MAX_TABLE_COUNT]; if (md->key != ent->key) continue; diff --git a/src/core/transport/chttp2/internal.h b/src/core/transport/chttp2/internal.h index 125cd744b7..c8c1abb750 100644 --- a/src/core/transport/chttp2/internal.h +++ b/src/core/transport/chttp2/internal.h @@ -168,7 +168,7 @@ typedef struct { grpc_iomgr_closure *pending_closures_tail; /** 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 */ gpr_uint32 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_slice goaway_text; - gpr_uint64 outgoing_window_update; + gpr_int64 outgoing_window_update; /** pings awaiting responses */ grpc_chttp2_outstanding_ping pings; diff --git a/src/core/transport/chttp2/parsing.c b/src/core/transport/chttp2/parsing.c index 5d3dfe2286..a592ce7d28 100644 --- a/src/core/transport/chttp2/parsing.c +++ b/src/core/transport/chttp2/parsing.c @@ -411,7 +411,7 @@ int grpc_chttp2_perform_read(grpc_chttp2_transport_parsing *transport_parsing, 0)) { return 0; } - transport_parsing->incoming_frame_size -= (end - cur); + transport_parsing->incoming_frame_size -= (gpr_uint32)(end - cur); return 1; } 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( grpc_chttp2_transport_parsing *transport_parsing, int 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_data = &transport_parsing->hpack_parser; 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( grpc_chttp2_transport_parsing *transport_parsing, int is_continuation) { - int is_eoh = (transport_parsing->incoming_frame_flags & - GRPC_CHTTP2_DATA_FLAG_END_HEADERS) != 0; + gpr_uint8 is_eoh = (transport_parsing->incoming_frame_flags & + GRPC_CHTTP2_DATA_FLAG_END_HEADERS) != 0; int via_accept = 0; grpc_chttp2_stream_parsing *stream_parsing; diff --git a/src/core/transport/chttp2/stream_encoder.c b/src/core/transport/chttp2/stream_encoder.c index 8c30af652f..6a22532bc2 100644 --- a/src/core/transport/chttp2/stream_encoder.c +++ b/src/core/transport/chttp2/stream_encoder.c @@ -77,15 +77,15 @@ typedef struct { static void fill_header(gpr_uint8 *p, gpr_uint8 type, gpr_uint32 id, size_t len, gpr_uint8 flags) { GPR_ASSERT(len < 16777316); - *p++ = len >> 16; - *p++ = len >> 8; - *p++ = len; + *p++ = (gpr_uint8)(len >> 16); + *p++ = (gpr_uint8)(len >> 8); + *p++ = (gpr_uint8)(len); *p++ = type; *p++ = flags; - *p++ = id >> 24; - *p++ = id >> 16; - *p++ = id >> 8; - *p++ = id; + *p++ = (gpr_uint8)(id >> 24); + *p++ = (gpr_uint8)(id >> 16); + *p++ = (gpr_uint8)(id >> 8); + *p++ = (gpr_uint8)(id); } /* 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: return; } - fill_header(GPR_SLICE_START_PTR(st->output->slices[st->header_idx]), type, - st->stream_id, - st->output->length - st->output_length_at_start_of_frame, - (is_last_in_stream ? GRPC_CHTTP2_DATA_FLAG_END_STREAM : 0) | - (is_header_boundary ? GRPC_CHTTP2_DATA_FLAG_END_HEADERS : 0)); + fill_header( + GPR_SLICE_START_PTR(st->output->slices[st->header_idx]), type, + st->stream_id, st->output->length - st->output_length_at_start_of_frame, + (gpr_uint8)( + (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; } @@ -190,6 +191,8 @@ static grpc_mdelem *add_elem(grpc_chttp2_hpack_compressor *c, GPR_SLICE_LENGTH(elem->value->slice); grpc_mdelem *elem_to_unref; + GPR_ASSERT(elem_size < 65536); + /* Reserve space for this element in the remote table: if this overflows the current table, drop elements until it fits, matching the decompressor algorithm */ @@ -201,14 +204,16 @@ static grpc_mdelem *add_elem(grpc_chttp2_hpack_compressor *c, c->table_elem_size[c->tail_remote_index % GRPC_CHTTP2_HPACKC_MAX_TABLE_ELEMS]); GPR_ASSERT(c->table_elems > 0); - c->table_size -= c->table_elem_size[c->tail_remote_index % - GRPC_CHTTP2_HPACKC_MAX_TABLE_ELEMS]; + c->table_size = + (gpr_uint16)(c->table_size - + c->table_elem_size[c->tail_remote_index % + GRPC_CHTTP2_HPACKC_MAX_TABLE_ELEMS]); c->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] = - elem_size; - c->table_size += elem_size; + (gpr_uint16)elem_size; + c->table_size = (gpr_uint16)(c->table_size + elem_size); c->table_elems++; /* 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 curop = 0; gpr_uint8 *p; - int compressed_flag_set = 0; + gpr_uint8 compressed_flag_set = 0; while (curop < *inops_count) { 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[0] = compressed_flag_set; - p[1] = op->data.begin_message.length >> 24; - p[2] = op->data.begin_message.length >> 16; - p[3] = op->data.begin_message.length >> 8; - p[4] = op->data.begin_message.length; + p[1] = (gpr_uint8)(op->data.begin_message.length >> 24); + p[2] = (gpr_uint8)(op->data.begin_message.length >> 16); + p[3] = (gpr_uint8)(op->data.begin_message.length >> 8); + p[4] = (gpr_uint8)(op->data.begin_message.length); op->type = GRPC_OP_SLICE; op->data.slice = slice; /* fallthrough */ @@ -550,7 +555,7 @@ gpr_uint32 grpc_chttp2_preencode(grpc_stream_op *inops, size_t *inops_count, grpc_sopb_append(outops, op, 1); curop++; } - flow_controlled_bytes_taken += GPR_SLICE_LENGTH(slice); + flow_controlled_bytes_taken += (gpr_uint32)GPR_SLICE_LENGTH(slice); break; } } diff --git a/src/core/transport/chttp2/varint.h b/src/core/transport/chttp2/varint.h index 37856913f8..4dfcc76773 100644 --- a/src/core/transport/chttp2/varint.h +++ b/src/core/transport/chttp2/varint.h @@ -63,7 +63,7 @@ void grpc_chttp2_hpack_write_varint_tail(gpr_uint32 tail_value, do { \ gpr_uint8* tgt = target; \ if ((length) == 1u) { \ - (tgt)[0] = (prefix_or) | (n); \ + (tgt)[0] = (gpr_uint8)((prefix_or) | (n)); \ } else { \ (tgt)[0] = (prefix_or) | GRPC_CHTTP2_MAX_IN_PREFIX(prefix_bits); \ grpc_chttp2_hpack_write_varint_tail( \ diff --git a/src/core/transport/chttp2_transport.c b/src/core/transport/chttp2_transport.c index c80330527e..deb2fedf0c 100644 --- a/src/core/transport/chttp2_transport.c +++ b/src/core/transport/chttp2_transport.c @@ -209,7 +209,7 @@ static void ref_transport(grpc_chttp2_transport *t) { gpr_ref(&t->refs); } static void init_transport(grpc_chttp2_transport *t, const grpc_channel_args *channel_args, grpc_endpoint *ep, grpc_mdctx *mdctx, - int is_client) { + gpr_uint8 is_client) { size_t i; int j; @@ -683,6 +683,8 @@ static void perform_stream_op_locked( stream_global->publish_sopb = op->recv_ops; stream_global->publish_sopb->nops = 0; 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) { GRPC_CHTTP2_FLOWCTL_TRACE_STREAM( "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->max_recv_bytes - stream_global->max_recv_bytes); stream_global->unannounced_incoming_window += - op->max_recv_bytes - stream_global->max_recv_bytes; - stream_global->max_recv_bytes = - (gpr_uint32)(GPR_MIN(op->max_recv_bytes, GPR_UINT32_MAX)); + (gpr_uint32)op->max_recv_bytes - stream_global->max_recv_bytes; + stream_global->max_recv_bytes = (gpr_uint32)op->max_recv_bytes; } grpc_chttp2_incoming_metadata_live_op_buffer_end( &stream_global->outstanding_metadata); @@ -730,14 +731,14 @@ static void send_ping_locked(grpc_chttp2_transport *t, p->next = &t->global.pings; p->prev = p->next->prev; p->prev->next = p->next->prev = p; - p->id[0] = (t->global.ping_counter >> 56) & 0xff; - p->id[1] = (t->global.ping_counter >> 48) & 0xff; - p->id[2] = (t->global.ping_counter >> 40) & 0xff; - p->id[3] = (t->global.ping_counter >> 32) & 0xff; - p->id[4] = (t->global.ping_counter >> 24) & 0xff; - p->id[5] = (t->global.ping_counter >> 16) & 0xff; - p->id[6] = (t->global.ping_counter >> 8) & 0xff; - p->id[7] = t->global.ping_counter & 0xff; + p->id[0] = (gpr_uint8)((t->global.ping_counter >> 56) & 0xff); + p->id[1] = (gpr_uint8)((t->global.ping_counter >> 48) & 0xff); + p->id[2] = (gpr_uint8)((t->global.ping_counter >> 40) & 0xff); + p->id[3] = (gpr_uint8)((t->global.ping_counter >> 32) & 0xff); + p->id[4] = (gpr_uint8)((t->global.ping_counter >> 24) & 0xff); + p->id[5] = (gpr_uint8)((t->global.ping_counter >> 16) & 0xff); + p->id[6] = (gpr_uint8)((t->global.ping_counter >> 8) & 0xff); + p->id[7] = (gpr_uint8)(t->global.ping_counter & 0xff); p->on_recv = on_recv; 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)); } 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) { 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++ = 'g'; *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)); - len += GPR_SLICE_LENGTH(message_pfx); - len += GPR_SLICE_LENGTH(*optional_message); + len += (gpr_uint32)GPR_SLICE_LENGTH(message_pfx); + len += (gpr_uint32)GPR_SLICE_LENGTH(*optional_message); } hdr = gpr_slice_malloc(9); p = GPR_SLICE_START_PTR(hdr); - *p++ = len >> 16; - *p++ = len >> 8; - *p++ = len; + *p++ = (gpr_uint8)(len >> 16); + *p++ = (gpr_uint8)(len >> 8); + *p++ = (gpr_uint8)(len); *p++ = GRPC_CHTTP2_FRAME_HEADER; *p++ = GRPC_CHTTP2_DATA_FLAG_END_STREAM | GRPC_CHTTP2_DATA_FLAG_END_HEADERS; - *p++ = stream_global->id >> 24; - *p++ = stream_global->id >> 16; - *p++ = stream_global->id >> 8; - *p++ = stream_global->id; + *p++ = (gpr_uint8)(stream_global->id >> 24); + *p++ = (gpr_uint8)(stream_global->id >> 16); + *p++ = (gpr_uint8)(stream_global->id >> 8); + *p++ = (gpr_uint8)(stream_global->id); GPR_ASSERT(p == GPR_SLICE_END_PTR(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, int is_client) { 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; } diff --git a/src/core/transport/metadata.c b/src/core/transport/metadata.c index 9b07b980b7..9d135f4356 100644 --- a/src/core/transport/metadata.c +++ b/src/core/transport/metadata.c @@ -334,7 +334,7 @@ grpc_mdstr *grpc_mdstr_from_string(grpc_mdctx *ctx, const char *str, grpc_mdstr *ret; for (i = 0; i < len; i++) { if (str[i] >= 'A' && str[i] <= 'Z') { - copy[i] = str[i] - 'A' + 'a'; + copy[i] = (char)(str[i] - 'A' + 'a'); } else { 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; memcpy(s->slice.data.inlined.bytes, buf, length); s->slice.data.inlined.bytes[length] = 0; - s->slice.data.inlined.length = length; + s->slice.data.inlined.length = (gpr_uint8)length; } else { /* string data goes after the internal_string header, and we +1 for null terminator */ diff --git a/templates/Makefile.template b/templates/Makefile.template index d6bcb54bac..346b4f438c 100644 --- a/templates/Makefile.template +++ b/templates/Makefile.template @@ -247,10 +247,6 @@ 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) - # 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. # 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 @@ -265,10 +261,7 @@ DEFINES += $(EXTRA_DEFINES) endif - CFLAGS += -std=c89 -pedantic -Wsign-conversion - ifeq ($(HAS_SHORTEN_64_TO_32),true) - CFLAGS += -Wshorten-64-to-32 - endif + CFLAGS += -std=c89 -pedantic -Wsign-conversion -Wconversion ifeq ($(HAS_CXX11),true) CXXFLAGS += -std=c++11 else diff --git a/test/core/fling/client.c b/test/core/fling/client.c index ed80544e3c..a53411c2f5 100644 --- a/test/core/fling/client.c +++ b/test/core/fling/client.c @@ -130,7 +130,7 @@ static void step_ping_pong_stream(void) { static double now(void) { 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 { diff --git a/test/core/iomgr/endpoint_tests.c b/test/core/iomgr/endpoint_tests.c index 27123eb216..853b9a32c2 100644 --- a/test/core/iomgr/endpoint_tests.c +++ b/test/core/iomgr/endpoint_tests.c @@ -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 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); gpr_slice *slices = malloc(sizeof(gpr_slice) * nslices); 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]); for (j = 0; j < GPR_SLICE_LENGTH(slices[i]); ++j) { buf[j] = *current_data; - *current_data = (*current_data + 1) % 256; + (*current_data)++; } } GPR_ASSERT(num_bytes_left == 0); @@ -117,7 +117,7 @@ struct read_and_write_test_state { size_t current_write_size; size_t bytes_written; int current_read_data; - int current_write_data; + gpr_uint8 current_write_data; int read_done; int write_done; gpr_slice_buffer incoming; diff --git a/test/core/iomgr/fd_posix_test.c b/test/core/iomgr/fd_posix_test.c index af66ef0997..75959069c0 100644 --- a/test/core/iomgr/fd_posix_test.c +++ b/test/core/iomgr/fd_posix_test.c @@ -83,7 +83,8 @@ static void create_test_socket(int port, int *socket_fd, /* Use local address for test */ sin->sin_family = AF_INET; 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 */ diff --git a/test/core/iomgr/tcp_posix_test.c b/test/core/iomgr/tcp_posix_test.c index b94f5987ca..59c498edff 100644 --- a/test/core/iomgr/tcp_posix_test.c +++ b/test/core/iomgr/tcp_posix_test.c @@ -81,7 +81,7 @@ static ssize_t fill_socket(int fd) { int i; unsigned char buf[256]; for (i = 0; i < 256; ++i) { - buf[i] = i; + buf[i] = (gpr_uint8)i; } do { 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 i; for (i = 0; i < bytes; ++i) { - buf[i] = i % 256; + buf[i] = (gpr_uint8)(i % 256); } do { @@ -276,7 +276,7 @@ struct write_socket_state { }; 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); gpr_slice *slices = gpr_malloc(sizeof(gpr_slice) * nslices); 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]); for (j = 0; j < GPR_SLICE_LENGTH(slices[i]); ++j) { buf[j] = *current_data; - *current_data = (*current_data + 1) % 256; + (*current_data)++; } } 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; size_t num_blocks; gpr_slice *slices; - int current_data = 0; + gpr_uint8 current_data = 0; gpr_slice_buffer outgoing; grpc_iomgr_closure write_done_closure; gpr_timespec deadline = GRPC_TIMEOUT_SECONDS_TO_DEADLINE(20); diff --git a/test/core/iomgr/udp_server_test.c b/test/core/iomgr/udp_server_test.c index 8c964246c7..c4f1896ba6 100644 --- a/test/core/iomgr/udp_server_test.c +++ b/test/core/iomgr/udp_server_test.c @@ -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); 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); gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset)); diff --git a/test/core/json/json_rewrite.c b/test/core/json/json_rewrite.c index 561bf487b9..82cc4090f3 100644 --- a/test/core/json/json_rewrite.c +++ b/test/core/json/json_rewrite.c @@ -34,8 +34,9 @@ #include #include -#include #include +#include +#include #include "src/core/json/json_reader.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) { json_reader_userdata* state = userdata; 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) { diff --git a/test/core/json/json_rewrite_test.c b/test/core/json/json_rewrite_test.c index 7cf184950e..d26ef53b2d 100644 --- a/test/core/json/json_rewrite_test.c +++ b/test/core/json/json_rewrite_test.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) { json_reader_userdata* state = userdata; 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) { diff --git a/test/core/support/slice_test.c b/test/core/support/slice_test.c index a84ad50cf3..1d202f0618 100644 --- a/test/core/support/slice_test.c +++ b/test/core/support/slice_test.c @@ -116,7 +116,7 @@ static void test_slice_sub_works(unsigned length) { beginning of the slice. */ slice = gpr_slice_malloc(length); 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 @@ -155,7 +155,7 @@ static void test_slice_split_head_works(size_t length) { beginning of the slice. */ slice = gpr_slice_malloc(length); 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 @@ -183,7 +183,7 @@ static void test_slice_split_tail_works(size_t length) { beginning of the slice. */ slice = gpr_slice_malloc(length); 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 diff --git a/test/core/transport/chttp2/stream_encoder_test.c b/test/core/transport/chttp2/stream_encoder_test.c index a723b90084..71db98c69e 100644 --- a/test/core/transport/chttp2/stream_encoder_test.c +++ b/test/core/transport/chttp2/stream_encoder_test.c @@ -59,7 +59,7 @@ static gpr_slice create_test_slice(size_t length) { gpr_slice slice = gpr_slice_malloc(length); size_t 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; } @@ -196,10 +196,10 @@ static void test_basic_headers(void) { } static void encode_int_to_str(int i, char *p) { - p[0] = 'a' + i % 26; + p[0] = (char)('a' + i % 26); i /= 26; GPR_ASSERT(i < 26); - p[1] = 'a' + i; + p[1] = (char)('a' + i); p[2] = 0; } @@ -246,7 +246,7 @@ static void randstr(char *p, int bufsz) { int i; int len = 1 + rand() % bufsz; for (i = 0; i < len; i++) { - p[i] = 'a' + rand() % 26; + p[i] = (char)('a' + rand() % 26); } p[len] = 0; } diff --git a/test/core/util/parse_hexstring.c b/test/core/util/parse_hexstring.c index 0bac8fef32..eced3173d1 100644 --- a/test/core/util/parse_hexstring.c +++ b/test/core/util/parse_hexstring.c @@ -54,10 +54,10 @@ gpr_slice parse_hexstring(const char *hexstring) { temp = 0; for (p = hexstring; *p; p++) { if (*p >= '0' && *p <= '9') { - temp = (temp << 4) | (*p - '0'); + temp = (gpr_uint8)(temp << 4) | (gpr_uint8)(*p - '0'); nibbles++; } else if (*p >= 'a' && *p <= 'f') { - temp = (temp << 4) | (*p - 'a' + 10); + temp = (gpr_uint8)(temp << 4) | (gpr_uint8)(*p - 'a' + 10); nibbles++; } if (nibbles == 2) { diff --git a/test/core/util/port_posix.c b/test/core/util/port_posix.c index 4781d334e2..be45bae496 100644 --- a/test/core/util/port_posix.c +++ b/test/core/util/port_posix.c @@ -102,7 +102,7 @@ static int is_port_available(int *port, int is_tcp) { /* Try binding to port */ addr.sin_family = AF_INET; 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) { gpr_log(GPR_DEBUG, "bind(port=%d) failed: %s", *port, strerror(errno)); close(fd); diff --git a/test/core/util/reconnect_server.c b/test/core/util/reconnect_server.c index aa7f77eadf..71fb69b54f 100644 --- a/test/core/util/reconnect_server.c +++ b/test/core/util/reconnect_server.c @@ -116,7 +116,7 @@ void reconnect_server_start(reconnect_server *server, int port) { int port_added; 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)); server->tcp_server = grpc_tcp_server_create(); diff --git a/test/core/util/test_config.h b/test/core/util/test_config.h index ccef8620c1..15b71747fb 100644 --- a/test/core/util/test_config.h +++ b/test/core/util/test_config.h @@ -54,15 +54,17 @@ extern double g_fixture_slowdown_factor; (GRPC_TEST_SLOWDOWN_BUILD_FACTOR * GRPC_TEST_SLOWDOWN_MACHINE_FACTOR * \ g_fixture_slowdown_factor) -#define GRPC_TIMEOUT_SECONDS_TO_DEADLINE(x) \ - gpr_time_add(gpr_now(GPR_CLOCK_MONOTONIC), \ - gpr_time_from_millis(GRPC_TEST_SLOWDOWN_FACTOR * 1e3 * (x), \ - GPR_TIMESPAN)) +#define GRPC_TIMEOUT_SECONDS_TO_DEADLINE(x) \ + gpr_time_add( \ + gpr_now(GPR_CLOCK_MONOTONIC), \ + gpr_time_from_millis((long)(GRPC_TEST_SLOWDOWN_FACTOR * 1e3 * (x)), \ + GPR_TIMESPAN)) -#define GRPC_TIMEOUT_MILLIS_TO_DEADLINE(x) \ - gpr_time_add(gpr_now(GPR_CLOCK_MONOTONIC), \ - gpr_time_from_micros(GRPC_TEST_SLOWDOWN_FACTOR * 1e3 * (x), \ - GPR_TIMESPAN)) +#define GRPC_TIMEOUT_MILLIS_TO_DEADLINE(x) \ + gpr_time_add( \ + gpr_now(GPR_CLOCK_MONOTONIC), \ + gpr_time_from_micros((long)(GRPC_TEST_SLOWDOWN_FACTOR * 1e3 * (x)), \ + GPR_TIMESPAN)) #ifndef GRPC_TEST_CUSTOM_PICK_PORT #define GRPC_TEST_PICK_PORT diff --git a/tools/codegen/core/gen_hpack_tables.c b/tools/codegen/core/gen_hpack_tables.c index dec0e2f3fe..d924aba602 100644 --- a/tools/codegen/core/gen_hpack_tables.c +++ b/tools/codegen/core/gen_hpack_tables.c @@ -71,13 +71,13 @@ static unsigned char prefix_mask(unsigned char prefix_len) { unsigned char i; unsigned char out = 0; for (i = 0; i < prefix_len; i++) { - out |= 1 << (7 - i); + out |= (unsigned char)(1 << (7 - i)); } return out; } 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) { @@ -92,7 +92,7 @@ static void generate_first_byte_lut(void) { chrspec = NULL; for (j = 0; j < num_fields; j++) { 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 (fields[j].index != 2) continue; } else if (suffix == 0) { @@ -336,7 +336,7 @@ static void generate_base64_inverse_table(void) { memset(inverse, 255, sizeof(inverse)); 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] = {"); diff --git a/tools/codegen/core/gen_legal_metadata_characters.c b/tools/codegen/core/gen_legal_metadata_characters.c index 0fbc545d8d..2ffda54a21 100644 --- a/tools/codegen/core/gen_legal_metadata_characters.c +++ b/tools/codegen/core/gen_legal_metadata_characters.c @@ -41,7 +41,7 @@ static unsigned char legal_bits[256 / 8]; static void legal(int x) { int byte = x / 8; int bit = x % 8; - legal_bits[byte] |= 1 << bit; + legal_bits[byte] |= (unsigned char)(1 << bit); } static void dump(void) { -- cgit v1.2.3