Fix warning with gcc

This commit is contained in:
Tatsuhiro Tsujikawa 2015-09-23 18:07:38 +09:00
parent 28fe3e7e89
commit 170f2a144a
16 changed files with 66 additions and 54 deletions

View File

@ -132,7 +132,7 @@ static void deflate(nghttp2_hd_deflater *deflater,
outlen = (size_t)rv;
printf("\nDeflate (%zu byte(s), ratio %.02f):\n\n", outlen,
sum == 0 ? 0 : (double)outlen / sum);
sum == 0 ? 0 : (double)outlen / (double)sum);
for (i = 0; i < outlen; ++i) {
if ((i & 0x0fu) == 0) {

View File

@ -120,7 +120,7 @@ static http2_stream_data *create_http2_stream_data(const char *uri,
}
if (u->field_set & (1 << UF_QUERY)) {
/* +1 for '?' character */
stream_data->pathlen += u->field_data[UF_QUERY].len + 1;
stream_data->pathlen += (size_t)(u->field_data[UF_QUERY].len + 1);
}
stream_data->path = malloc(stream_data->pathlen);

View File

@ -312,13 +312,13 @@ static int ends_with(const char *s, const char *sub) {
/* Returns int value of hex string character |c| */
static uint8_t hex_to_uint(uint8_t c) {
if ('0' <= c && c <= '9') {
return c - '0';
return (uint8_t)(c - '0');
}
if ('A' <= c && c <= 'F') {
return c - 'A' + 10;
return (uint8_t)(c - 'A' + 10);
}
if ('a' <= c && c <= 'f') {
return c - 'a' + 10;
return (uint8_t)(c - 'a' + 10);
}
return 0;
}
@ -340,7 +340,7 @@ static char *percent_decode(const uint8_t *value, size_t valuelen) {
continue;
}
res[j++] =
(char)(hex_to_uint(value[i + 1]) << 4) + hex_to_uint(value[i + 2]);
(char)((hex_to_uint(value[i + 1]) << 4) + hex_to_uint(value[i + 2]));
i += 3;
}
memcpy(&res[j], &value[i], 2);

View File

@ -248,7 +248,7 @@ static char *cpydig(char *buf, int n, size_t len) {
p = buf + len - 1;
do {
*p-- = (n % 10) + '0';
*p-- = (char)((n % 10) + '0');
n /= 10;
} while (p >= buf);
@ -319,7 +319,7 @@ static size_t utos(char *buf, size_t len, uint64_t n) {
buf += nwrite - 1;
do {
*buf-- = (n % 10) + '0';
*buf-- = (char)((n % 10) + '0');
n /= 10;
} while (n);

View File

@ -300,12 +300,15 @@ int nghttp2_bufs_orb_hold(nghttp2_bufs *bufs, uint8_t b);
#define nghttp2_bufs_fast_orb(BUFS, B) \
do { \
*(BUFS)->cur->buf.last++ |= B; \
uint8_t **p = &(BUFS)->cur->buf.last; \
**p = (uint8_t)(**p | (B)); \
++(*p); \
} while (0)
#define nghttp2_bufs_fast_orb_hold(BUFS, B) \
do { \
*(BUFS)->cur->buf.last |= B; \
uint8_t *p = (BUFS)->cur->buf.last; \
*p = (uint8_t)(*p | (B)); \
} while (0)
/*

View File

@ -219,7 +219,7 @@ static int frame_pack_headers_shared(nghttp2_bufs *bufs,
CONTINUATION frame is involved. Remove END_HEADERS flag from the
first frame. */
if (bufs->head != bufs->cur) {
hd.flags &= ~NGHTTP2_FLAG_END_HEADERS;
hd.flags = (uint8_t)(hd.flags & ~NGHTTP2_FLAG_END_HEADERS);
}
buf->pos -= NGHTTP2_FRAME_HDLEN;

View File

@ -506,7 +506,7 @@ int nghttp2_hd_entry_init(nghttp2_hd_entry *ent, uint8_t flags, uint8_t *name,
if ((flags & NGHTTP2_HD_FLAG_NAME_ALLOC) &&
(flags & NGHTTP2_HD_FLAG_NAME_GIFT) == 0) {
if (namelen == 0) {
flags &= ~NGHTTP2_HD_FLAG_NAME_ALLOC;
flags = (uint8_t)(flags & ~NGHTTP2_HD_FLAG_NAME_ALLOC);
ent->nv.name = (uint8_t *)"";
} else {
/* copy including terminating NULL byte */
@ -522,7 +522,7 @@ int nghttp2_hd_entry_init(nghttp2_hd_entry *ent, uint8_t flags, uint8_t *name,
if ((flags & NGHTTP2_HD_FLAG_VALUE_ALLOC) &&
(flags & NGHTTP2_HD_FLAG_VALUE_GIFT) == 0) {
if (valuelen == 0) {
flags &= ~NGHTTP2_HD_FLAG_VALUE_ALLOC;
flags = (uint8_t)(flags & ~NGHTTP2_HD_FLAG_VALUE_ALLOC);
ent->nv.value = (uint8_t *)"";
} else {
/* copy including terminating NULL byte */
@ -877,7 +877,7 @@ static int emit_literal_header(nghttp2_nv *nv_out, int *token_out,
}
static size_t count_encoded_length(size_t n, size_t prefix) {
size_t k = (1 << prefix) - 1;
size_t k = (size_t)((1 << prefix) - 1);
size_t len = 0;
if (n < k) {
@ -894,21 +894,23 @@ static size_t count_encoded_length(size_t n, size_t prefix) {
}
static size_t encode_length(uint8_t *buf, size_t n, size_t prefix) {
size_t k = (1 << prefix) - 1;
size_t k = (size_t)((1 << prefix) - 1);
uint8_t *begin = buf;
*buf &= ~k;
*buf = (uint8_t)(*buf & ~k);
if (n < k) {
*buf |= n;
*buf = (uint8_t)(*buf | n);
return 1;
}
*buf++ |= k;
*buf = (uint8_t)(*buf | k);
++buf;
n -= k;
for (; n >= 128; n >>= 7) {
*buf++ = (1 << 7) | (n & 0x7f);
*buf++ = (uint8_t)((1 << 7) | (n & 0x7f));
}
*buf++ = (uint8_t)n;
@ -936,7 +938,7 @@ static size_t encode_length(uint8_t *buf, size_t n, size_t prefix) {
static ssize_t decode_length(uint32_t *res, size_t *shift_ptr, int *final,
uint32_t initial, size_t shift, uint8_t *in,
uint8_t *last, size_t prefix) {
uint32_t k = (1 << prefix) - 1;
uint32_t k = (uint8_t)((1 << prefix) - 1);
uint32_t n = initial;
uint8_t *start = in;

View File

@ -48,17 +48,17 @@ static ssize_t huff_encode_sym(nghttp2_bufs *bufs, size_t *avail_ptr,
/* We assume that sym->nbits <= 32 */
if (rembits > nbits) {
nghttp2_bufs_fast_orb_hold(bufs, code << (rembits - nbits));
nghttp2_bufs_fast_orb_hold(bufs, (uint8_t)(code << (rembits - nbits)));
return (ssize_t)(rembits - nbits);
}
if (rembits == nbits) {
nghttp2_bufs_fast_orb(bufs, code);
nghttp2_bufs_fast_orb(bufs, (uint8_t)code);
--*avail_ptr;
return 8;
}
nghttp2_bufs_fast_orb(bufs, code >> (nbits - rembits));
nghttp2_bufs_fast_orb(bufs, (uint8_t)(code >> (nbits - rembits)));
--*avail_ptr;
nbits -= rembits;
@ -87,7 +87,7 @@ static ssize_t huff_encode_sym(nghttp2_bufs *bufs, size_t *avail_ptr,
/* handle longer code path */
if (nbits > 24) {
nghttp2_bufs_fast_addb(bufs, code >> 24);
nghttp2_bufs_fast_addb(bufs, (uint8_t)(code >> 24));
nbits -= 8;
}
@ -157,7 +157,7 @@ int nghttp2_hd_huff_encode(nghttp2_bufs *bufs, const uint8_t *src,
const nghttp2_huff_sym *sym = &huff_sym_table[256];
assert(avail);
/* Caution we no longer adjust avail here */
nghttp2_bufs_fast_orb(bufs, sym->code >> (sym->nbits - rembits));
nghttp2_bufs_fast_orb(bufs, (uint8_t)(sym->code >> (sym->nbits - rembits)));
}
return 0;

View File

@ -32,7 +32,7 @@
#include "nghttp2_helper.h"
static uint8_t downcase(uint8_t c) {
return 'A' <= c && c <= 'Z' ? (c - 'A' + 'a') : c;
return 'A' <= c && c <= 'Z' ? (uint8_t)(c - 'A' + 'a') : c;
}
static int memieq(const void *a, const void *b, size_t n) {
@ -90,7 +90,7 @@ static int check_pseudo_header(nghttp2_stream *stream, const nghttp2_nv *nv,
if (lws(nv->value, nv->valuelen)) {
return 0;
}
stream->http_flags |= flag;
stream->http_flags = (uint16_t)(stream->http_flags | flag);
return 1;
}
@ -368,14 +368,16 @@ int nghttp2_http_on_response_headers(nghttp2_stream *stream) {
if (stream->status_code / 100 == 1) {
/* non-final response */
stream->http_flags = (stream->http_flags & NGHTTP2_HTTP_FLAG_METH_ALL) |
NGHTTP2_HTTP_FLAG_EXPECT_FINAL_RESPONSE;
stream->http_flags =
(uint16_t)((stream->http_flags & NGHTTP2_HTTP_FLAG_METH_ALL) |
NGHTTP2_HTTP_FLAG_EXPECT_FINAL_RESPONSE);
stream->content_length = -1;
stream->status_code = -1;
return 0;
}
stream->http_flags &= ~NGHTTP2_HTTP_FLAG_EXPECT_FINAL_RESPONSE;
stream->http_flags =
(uint16_t)(stream->http_flags & ~NGHTTP2_HTTP_FLAG_EXPECT_FINAL_RESPONSE);
if (!expect_response_body(stream)) {
stream->content_length = 0;
@ -409,7 +411,7 @@ int nghttp2_http_on_remote_end_stream(nghttp2_stream *stream) {
}
int nghttp2_http_on_data_chunk(nghttp2_stream *stream, size_t n) {
stream->recv_content_length += n;
stream->recv_content_length += (int64_t)n;
if ((stream->http_flags & NGHTTP2_HTTP_FLAG_EXPECT_FINAL_RESPONSE) ||
(stream->content_length != -1 &&

View File

@ -30,7 +30,7 @@ static int select_next_protocol(unsigned char **out, unsigned char *outlen,
const unsigned char *in, unsigned int inlen,
const char *key, unsigned int keylen) {
unsigned int i;
for (i = 0; i + keylen <= inlen; i += in [i] + 1) {
for (i = 0; i + keylen <= inlen; i += (unsigned int)(in [i] + 1)) {
if (memcmp(&in[i], key, keylen) == 0) {
*out = (unsigned char *)&in[i + 1];
*outlen = in[i];

View File

@ -2276,7 +2276,7 @@ static int session_after_frame_sent1(nghttp2_session *session) {
break;
}
case NGHTTP2_HCAT_PUSH_RESPONSE:
stream->flags &= ~NGHTTP2_STREAM_FLAG_PUSH;
stream->flags = (uint8_t)(stream->flags & ~NGHTTP2_STREAM_FLAG_PUSH);
++session->num_outgoing_streams;
/* Fall through */
case NGHTTP2_HCAT_RESPONSE:
@ -2372,9 +2372,9 @@ static int session_after_frame_sent1(nghttp2_session *session) {
/* We update flow control window after a frame was completely
sent. This is possible because we choose payload length not to
exceed the window */
session->remote_window_size -= frame->hd.length;
session->remote_window_size -= (int32_t)frame->hd.length;
if (stream) {
stream->remote_window_size -= frame->hd.length;
stream->remote_window_size -= (int32_t)frame->hd.length;
}
if (stream && aux_data->eof) {
@ -4374,7 +4374,7 @@ static int adjust_recv_window_size(int32_t *recv_window_size_ptr, size_t delta,
*recv_window_size_ptr > NGHTTP2_MAX_WINDOW_SIZE - (int32_t)delta) {
return -1;
}
*recv_window_size_ptr += delta;
*recv_window_size_ptr += (int32_t)delta;
return 0;
}
@ -4474,7 +4474,7 @@ static int session_update_consumed_size(nghttp2_session *session,
NGHTTP2_FLOW_CONTROL_ERROR);
}
*consumed_size_ptr += delta_size;
*consumed_size_ptr += (int32_t)delta_size;
/* recv_window_size may be smaller than consumed_size, because it
may be decreased by negative value with
@ -4681,7 +4681,7 @@ static ssize_t inbound_frame_compute_pad(nghttp2_inbound_frame *iframe) {
size_t padlen;
/* 1 for Pad Length field */
padlen = iframe->sbuf.pos[0] + 1;
padlen = (size_t)(iframe->sbuf.pos[0] + 1);
DEBUGF(fprintf(stderr, "recv: padlen=%zu\n", padlen));
@ -5580,7 +5580,8 @@ ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in,
/* CONTINUATION won't bear NGHTTP2_PADDED flag */
iframe->frame.hd.flags |= cont_hd.flags & NGHTTP2_FLAG_END_HEADERS;
iframe->frame.hd.flags = (uint8_t)(
iframe->frame.hd.flags | (cont_hd.flags & NGHTTP2_FLAG_END_HEADERS));
iframe->frame.hd.length += cont_hd.length;
busy = 1;

View File

@ -89,7 +89,7 @@ void nghttp2_stream_free(nghttp2_stream *stream) {
}
void nghttp2_stream_shutdown(nghttp2_stream *stream, nghttp2_shut_flag flag) {
stream->shut_flags |= flag;
stream->shut_flags = (uint8_t)(stream->shut_flags | flag);
}
/*
@ -424,7 +424,7 @@ int nghttp2_stream_detach_item(nghttp2_stream *stream) {
stream->stream_id, stream->item));
stream->item = NULL;
stream->flags &= ~NGHTTP2_STREAM_FLAG_DEFERRED_ALL;
stream->flags = (uint8_t)(stream->flags & ~NGHTTP2_STREAM_FLAG_DEFERRED_ALL);
return stream_update_dep_on_detach_item(stream);
}
@ -446,7 +446,7 @@ int nghttp2_stream_resume_deferred_item(nghttp2_stream *stream, uint8_t flags) {
DEBUGF(fprintf(stderr, "stream: stream=%d resume item=%p flags=%02x\n",
stream->stream_id, stream->item, flags));
stream->flags &= ~flags;
stream->flags = (uint8_t)(stream->flags & ~flags);
if (stream->flags & NGHTTP2_STREAM_FLAG_DEFERRED_ALL) {
return 0;
@ -495,7 +495,7 @@ int nghttp2_stream_update_local_initial_window_size(
void nghttp2_stream_promise_fulfilled(nghttp2_stream *stream) {
stream->state = NGHTTP2_STREAM_OPENED;
stream->flags &= ~NGHTTP2_STREAM_FLAG_PUSH;
stream->flags = (uint8_t)(stream->flags & ~NGHTTP2_STREAM_FLAG_PUSH);
}
int nghttp2_stream_dep_find_ancestor(nghttp2_stream *stream,

View File

@ -71,8 +71,9 @@ static int32_t submit_headers_shared(nghttp2_session *session, uint8_t flags,
item->aux_data.headers.stream_user_data = stream_user_data;
item->aux_data.headers.attach_stream = attach_stream;
flags_copy = (flags & (NGHTTP2_FLAG_END_STREAM | NGHTTP2_FLAG_PRIORITY)) |
NGHTTP2_FLAG_END_HEADERS;
flags_copy =
(uint8_t)((flags & (NGHTTP2_FLAG_END_STREAM | NGHTTP2_FLAG_PRIORITY)) |
NGHTTP2_FLAG_END_HEADERS);
if (stream_id == -1) {
if (session->next_stream_id > INT32_MAX) {

View File

@ -487,7 +487,7 @@ void test_nghttp2_nv_array_copy(void) {
CU_ASSERT(0 == rv);
CU_ASSERT(nva[0].namelen == 5);
CU_ASSERT(0 == memcmp("alpha", nva[0].name, 5));
CU_ASSERT(nva[0].valuelen = 5);
CU_ASSERT(nva[0].valuelen == 5);
CU_ASSERT(0 == memcmp("bravo", nva[0].value, 5));
CU_ASSERT(nva[1].namelen == 7);
CU_ASSERT(0 == memcmp("charlie", nva[1].name, 7));

View File

@ -1201,21 +1201,24 @@ void test_nghttp2_hd_public_api(void) {
}
static size_t encode_length(uint8_t *buf, uint64_t n, size_t prefix) {
size_t k = (1 << prefix) - 1;
size_t k = (size_t)((1 << prefix) - 1);
size_t len = 0;
*buf &= ~k;
*buf = (uint8_t)(*buf & ~k);
if (n >= k) {
*buf++ |= k;
*buf = (uint8_t)(*buf | k);
++buf;
n -= k;
++len;
} else {
*buf++ |= n;
*buf = (uint8_t)(*buf | n);
++buf;
return 1;
}
do {
++len;
if (n >= 128) {
*buf++ = (1 << 7) | (n & 0x7f);
*buf = (uint8_t)((1 << 7) | (n & 0x7f));
++buf;
n >>= 7;
} else {
*buf++ = (uint8_t)n;

View File

@ -328,7 +328,7 @@ static int send_data_callback(nghttp2_session *session _U_,
acc->length += NGHTTP2_FRAME_HDLEN;
if (frame->data.padlen) {
*(acc->buf + acc->length++) = (uint8_t)frame->data.padlen - 1;
*(acc->buf + acc->length++) = (uint8_t)(frame->data.padlen - 1);
}
acc->length += length;
@ -927,7 +927,7 @@ void test_nghttp2_session_recv_continuation(void) {
datalen = NGHTTP2_FRAME_HDLEN + 1;
buf->pos += NGHTTP2_FRAME_HDLEN + 1;
nghttp2_put_uint32be(data, (1 << 8) + data[3]);
nghttp2_put_uint32be(data, (uint32_t)((1 << 8) + data[3]));
/* First CONTINUATION, 2 bytes */
nghttp2_frame_hd_init(&cont_hd, 2, NGHTTP2_CONTINUATION, NGHTTP2_FLAG_NONE,
@ -1099,7 +1099,7 @@ void test_nghttp2_session_recv_headers_with_priority(void) {
buf = &bufs.head->buf;
/* Make payload shorter than required length to store priority
group */
nghttp2_put_uint32be(buf->pos, (4 << 8) + buf->pos[3]);
nghttp2_put_uint32be(buf->pos, (uint32_t)((4 << 8) + buf->pos[3]));
ud.frame_recv_cb_called = 0;