From: Christopher Faulet Date: Mon, 24 Feb 2020 14:09:24 +0000 (+0100) Subject: MINOR: htx: Use htx_find_offset() to truncate an HTX message X-Git-Tag: v2.2-dev4~44 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bb76aa4d37cce832a47e5890b49138fff52452d2;p=thirdparty%2Fhaproxy.git MINOR: htx: Use htx_find_offset() to truncate an HTX message The htx_truncate() function now uses htx_find_offset() to find the first block to start the truncation. --- diff --git a/src/htx.c b/src/htx.c index 1ee60dcbdd..82c788b5ac 100644 --- a/src/htx.c +++ b/src/htx.c @@ -422,18 +422,12 @@ struct htx_ret htx_find_offset(struct htx *htx, uint32_t offset) void htx_truncate(struct htx *htx, uint32_t offset) { struct htx_blk *blk; + struct htx_ret htxret = htx_find_offset(htx, offset); - for (blk = htx_get_head_blk(htx); blk && offset; blk = htx_get_next_blk(htx, blk)) { - uint32_t sz = htx_get_blksz(blk); - enum htx_blk_type type = htx_get_blk_type(blk); - - if (offset >= sz) { - offset -= sz; - continue; - } - if (type == HTX_BLK_DATA) - htx_change_blk_value_len(htx, blk, offset); - offset = 0; + blk = htxret.blk; + if (blk && htxret.ret && htx_get_blk_type(blk) == HTX_BLK_DATA) { + htx_change_blk_value_len(htx, blk, htxret.ret); + blk = htx_get_next_blk(htx, blk); } while (blk) blk = htx_remove_blk(htx, blk);