aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core
diff options
context:
space:
mode:
authorGravatar Craig Tiller <ctiller@google.com>2015-09-10 16:00:22 -0700
committerGravatar Craig Tiller <ctiller@google.com>2015-09-10 16:00:22 -0700
commit6a6b36c50300bcc33d761598591c4d1bd4f1f6aa (patch)
treefa6b9eeb5d9281258b42603465fab6fdbb101512 /src/core
parent2ed498151da3b68107312b6397dbff4b4f60e475 (diff)
Enable -Wconversion
Diffstat (limited to 'src/core')
-rw-r--r--src/core/channel/compress_filter.c5
-rw-r--r--src/core/client_config/resolvers/sockaddr_resolver.c4
-rw-r--r--src/core/iomgr/alarm.c6
-rw-r--r--src/core/iomgr/pollset_multipoller_with_poll_posix.c4
-rw-r--r--src/core/iomgr/pollset_posix.c2
-rw-r--r--src/core/iomgr/sockaddr_utils.c12
-rw-r--r--src/core/surface/call.c11
-rw-r--r--src/core/transport/chttp2/bin_encoder.c23
-rw-r--r--src/core/transport/chttp2/frame_data.c3
-rw-r--r--src/core/transport/chttp2/frame_goaway.c25
-rw-r--r--src/core/transport/chttp2/frame_rst_stream.c16
-rw-r--r--src/core/transport/chttp2/frame_settings.c22
-rw-r--r--src/core/transport/chttp2/frame_window_update.c16
-rw-r--r--src/core/transport/chttp2/hpack_parser.c18
-rw-r--r--src/core/transport/chttp2/hpack_table.c31
-rw-r--r--src/core/transport/chttp2/internal.h4
-rw-r--r--src/core/transport/chttp2/parsing.c8
-rw-r--r--src/core/transport/chttp2/stream_encoder.c49
-rw-r--r--src/core/transport/chttp2/varint.h2
-rw-r--r--src/core/transport/chttp2_transport.c49
-rw-r--r--src/core/transport/metadata.c4
21 files changed, 170 insertions, 144 deletions
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 */