]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: htx: Use htx_find_offset() to truncate an HTX message
authorChristopher Faulet <cfaulet@haproxy.com>
Mon, 24 Feb 2020 14:09:24 +0000 (15:09 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Fri, 6 Mar 2020 13:12:59 +0000 (14:12 +0100)
The htx_truncate() function now uses htx_find_offset() to find the first block
to start the truncation.

src/htx.c

index 1ee60dcbdd23c904090408a397d583c343ac4ba3..82c788b5ac63a54921353a0217a9e8752ab39898 100644 (file)
--- 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);