From c9b6371977d091f9e9087b6247d8e97d0df30606 Mon Sep 17 00:00:00 2001 From: Alexis La Goutte Date: Mon, 16 Jun 2014 18:52:11 +0200 Subject: [PATCH 1/2] When assertions is disable, there is a warning about unused check_index_range function Make the check for a valid index range a macro, so the compiler doesn't whine if it's not used, but it's available if it *is* used. --- lib/nghttp2_hd.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/nghttp2_hd.c b/lib/nghttp2_hd.c index 431dee5e..c9335a4c 100644 --- a/lib/nghttp2_hd.c +++ b/lib/nghttp2_hd.c @@ -993,10 +993,8 @@ static void clear_refset(nghttp2_hd_context *context) } } -static int check_index_range(nghttp2_hd_context *context, size_t idx) -{ - return idx < context->hd_table.len + STATIC_TABLE_LENGTH; -} +#define INDEX_RANGE_VALID(context, idx) \ + ((idx) < (context)->hd_table.len + STATIC_TABLE_LENGTH) static size_t get_max_index(nghttp2_hd_context *context) { @@ -1006,7 +1004,7 @@ static size_t get_max_index(nghttp2_hd_context *context) nghttp2_hd_entry* nghttp2_hd_table_get(nghttp2_hd_context *context, size_t idx) { - assert(check_index_range(context, idx)); + assert(INDEX_RANGE_VALID(context, idx)); if(idx < context->hd_table.len) { return hd_ringbuf_get(&context->hd_table, idx); } else { From 9a3cdeb7e6c9a054b9dd5fdd5bc2dce86df31440 Mon Sep 17 00:00:00 2001 From: Alexis La Goutte Date: Mon, 16 Jun 2014 19:17:49 +0200 Subject: [PATCH 2/2] Fix some other shorten-64-to-32 casting error found by MSVC (64bits) Thanks for Pascal --- lib/nghttp2_buf.c | 4 ++-- lib/nghttp2_hd.c | 32 ++++++++++++++++---------------- lib/nghttp2_hd_huffman.c | 4 ++-- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/lib/nghttp2_buf.c b/lib/nghttp2_buf.c index b0b2bd12..38b0d03b 100644 --- a/lib/nghttp2_buf.c +++ b/lib/nghttp2_buf.c @@ -236,7 +236,7 @@ ssize_t nghttp2_bufs_len(nghttp2_bufs *bufs) static ssize_t bufs_avail(nghttp2_bufs *bufs) { - return nghttp2_buf_avail(&bufs->cur->buf) + + return (ssize_t)nghttp2_buf_avail(&bufs->cur->buf) + (bufs->chunk_length - bufs->offset) * (bufs->max_chunk - bufs->chunk_used); } @@ -424,7 +424,7 @@ ssize_t nghttp2_bufs_remove(nghttp2_bufs *bufs, uint8_t **out) *out = res; - return len; + return (ssize_t)len; } void nghttp2_bufs_reset(nghttp2_bufs *bufs) diff --git a/lib/nghttp2_hd.c b/lib/nghttp2_hd.c index c9335a4c..33676efb 100644 --- a/lib/nghttp2_hd.c +++ b/lib/nghttp2_hd.c @@ -483,7 +483,7 @@ static size_t encode_length(uint8_t *buf, size_t n, size_t prefix) *buf++ = (1 << 7) | (n & 0x7f); n >>= 7; } else { - *buf++ = n; + *buf++ = (uint8_t)n; break; } } while(n); @@ -883,7 +883,7 @@ static search_result search_hd_table(nghttp2_hd_context *context, size_t i; uint32_t name_hash = hash(nv->name, nv->namelen); uint32_t value_hash = hash(nv->value, nv->valuelen); - ssize_t left = -1, right = STATIC_TABLE_LENGTH; + ssize_t left = -1, right = (ssize_t)STATIC_TABLE_LENGTH; int use_index = (nv->flags & NGHTTP2_NV_FLAG_NO_INDEX) == 0; if(use_index) { @@ -891,10 +891,10 @@ static search_result search_hd_table(nghttp2_hd_context *context, nghttp2_hd_entry *ent = hd_ringbuf_get(&context->hd_table, i); if(ent->name_hash == name_hash && name_eq(&ent->nv, nv)) { if(res.index == -1) { - res.index = i; + res.index = (ssize_t)i; } if(ent->value_hash == value_hash && value_eq(&ent->nv, nv)) { - res.index = i; + res.index = (ssize_t)i; res.name_value_match = 1; return res; } @@ -919,11 +919,11 @@ static search_result search_hd_table(nghttp2_hd_context *context, } if(name_eq(&ent->nv, nv)) { if(res.index == -1) { - res.index = context->hd_table.len + static_table[i].index; + res.index = (ssize_t)(context->hd_table.len + static_table[i].index); } if(use_index && ent->value_hash == value_hash && value_eq(&ent->nv, nv)) { - res.index = context->hd_table.len + static_table[i].index; + res.index = (ssize_t)(context->hd_table.len + static_table[i].index); res.name_value_match = 1; return res; } @@ -1274,7 +1274,7 @@ ssize_t nghttp2_hd_deflate_hd(nghttp2_hd_deflater *deflater, return rv; } - return buflen; + return (ssize_t)buflen; } size_t nghttp2_hd_deflate_bound(nghttp2_hd_deflater *deflater, @@ -1365,7 +1365,7 @@ static ssize_t hd_inflate_read_len(nghttp2_hd_inflater *inflater, maxlen)); return NGHTTP2_ERR_HEADER_COMP; } - return nin - in; + return (ssize_t)(nin - in); } /* @@ -1428,8 +1428,8 @@ static ssize_t hd_inflate_read(nghttp2_hd_inflater *inflater, if(rv != 0) { return rv; } - inflater->left -= len; - return len; + inflater->left -= (ssize_t)len; + return (ssize_t)len; } /* @@ -1758,7 +1758,7 @@ ssize_t nghttp2_hd_inflate_hd(nghttp2_hd_inflater *inflater, /* If rv == 1, no header was emitted */ if(rv == 0) { *inflate_flags |= NGHTTP2_HD_INFLATE_EMIT; - return in - first; + return (ssize_t)(in - first); } } else { inflater->index = inflater->left; @@ -1877,7 +1877,7 @@ ssize_t nghttp2_hd_inflate_hd(nghttp2_hd_inflater *inflater, } inflater->state = NGHTTP2_HD_STATE_OPCODE; *inflate_flags |= NGHTTP2_HD_INFLATE_EMIT; - return in - first; + return (ssize_t)(in - first); } if(inflater->huffman_encoded) { @@ -1918,7 +1918,7 @@ ssize_t nghttp2_hd_inflate_hd(nghttp2_hd_inflater *inflater, inflater->state = NGHTTP2_HD_STATE_OPCODE; *inflate_flags |= NGHTTP2_HD_INFLATE_EMIT; - return in - first; + return (ssize_t)(in - first); case NGHTTP2_HD_STATE_READ_VALUE: rv = hd_inflate_read(inflater, &inflater->nvbufs, in, last); if(rv < 0) { @@ -1950,7 +1950,7 @@ ssize_t nghttp2_hd_inflate_hd(nghttp2_hd_inflater *inflater, inflater->state = NGHTTP2_HD_STATE_OPCODE; *inflate_flags |= NGHTTP2_HD_INFLATE_EMIT; - return in - first; + return (ssize_t)(in - first); } } @@ -1978,13 +1978,13 @@ ssize_t nghttp2_hd_inflate_hd(nghttp2_hd_inflater *inflater, (ent->flags & NGHTTP2_HD_FLAG_EMIT) == 0) { emit_indexed_header(nv_out, ent); *inflate_flags |= NGHTTP2_HD_INFLATE_EMIT; - return in - first; + return (ssize_t)(in - first); } ent->flags &= ~NGHTTP2_HD_FLAG_EMIT; } *inflate_flags |= NGHTTP2_HD_INFLATE_FINAL; } - return in - first; + return (ssize_t)(in - first); almost_ok: if(in_final && inflater->state != NGHTTP2_HD_STATE_OPCODE) { diff --git a/lib/nghttp2_hd_huffman.c b/lib/nghttp2_hd_huffman.c index 860b38d4..c8857226 100644 --- a/lib/nghttp2_hd_huffman.c +++ b/lib/nghttp2_hd_huffman.c @@ -95,7 +95,7 @@ static ssize_t huff_encode_sym(nghttp2_bufs *bufs, size_t *avail_ptr, *avail_ptr = nghttp2_bufs_cur_avail(bufs); } } - return rembits; + return (ssize_t)rembits; } size_t nghttp2_hd_huff_encode_count(const uint8_t *src, size_t len) @@ -203,5 +203,5 @@ ssize_t nghttp2_hd_huff_decode(nghttp2_hd_huff_decode_context *ctx, if(final && !ctx->accept) { return NGHTTP2_ERR_HEADER_COMP; } - return i; + return (ssize_t)i; }