From a658f1367e07c1c5bf08e073f8ad04571a7230ab Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Sun, 20 Oct 2013 16:28:52 +0900 Subject: [PATCH] encode_length: Or-ing first byte with prefix mask So that we can preserve leading bits. --- lib/nghttp2_hd.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/nghttp2_hd.c b/lib/nghttp2_hd.c index 144b7db3..f23bfc04 100644 --- a/lib/nghttp2_hd.c +++ b/lib/nghttp2_hd.c @@ -485,12 +485,13 @@ static size_t encode_length(uint8_t *buf, size_t n, int prefix) { size_t k = (1 << prefix) - 1; size_t len = 0; + *buf &= ~k; if(n >= k) { - *buf++ = k; + *buf++ |= k; n -= k; ++len; } else { - *buf++ = n; + *buf++ |= n; return 1; } do { @@ -560,8 +561,8 @@ static int emit_indexed_block(uint8_t **buf_ptr, size_t *buflen_ptr, return rv; } bufp = *buf_ptr + *offset_ptr; + *bufp = 0x80u; encode_length(bufp, index, 7); - (*buf_ptr)[*offset_ptr] |= 0x80u; *offset_ptr += blocklen; return 0; } @@ -582,13 +583,11 @@ static int emit_indname_block(uint8_t **buf_ptr, size_t *buflen_ptr, return rv; } bufp = *buf_ptr + *offset_ptr; + *bufp = inc_indexing ? 0 : 0x40u; bufp += encode_length(bufp, index + 1, 6); bufp += encode_length(bufp, encvallen, 8); nghttp2_hd_huff_encode(bufp, *buflen_ptr - (bufp - *buf_ptr), value, valuelen, side); - if(!inc_indexing) { - (*buf_ptr)[*offset_ptr] |= 0x40u; - } assert(bufp+encvallen - (*buf_ptr + *offset_ptr) == (ssize_t)blocklen); *offset_ptr += blocklen; return 0;