]> git.ipfire.org Git - thirdparty/haproxy.git/commit
CLEANUP: http-conv: index the captures array with hdr->index in the converters
authorWilly Tarreau <w@1wt.eu>
Mon, 27 Jul 2026 10:03:39 +0000 (12:03 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Mon, 27 Jul 2026 13:32:11 +0000 (15:32 +0200)
commit449d4e581c6b47621d6a3cfd925fa587c640bee4
treede228f3b393c0c877c6c48ad08a47bd118f546ea
parentf571e23cc0e844d5be3360c937886ad46cf1f0cb
CLEANUP: http-conv: index the captures array with hdr->index in the converters

smp_conv_req_capture() and smp_conv_res_capture() look the capture slot up by
walking the proxy's capture list backwards until the decreasing counter matches
the requested id, then allocate the storage using <hdr->index> but write it
using <idx>:

if (smp->strm->req_cap[hdr->index] == NULL)
smp->strm->req_cap[hdr->index] = pool_alloc(hdr->pool);
...
memcpy(smp->strm->req_cap[idx], smp->data.u.str.area, len);

Both are in fact always equal, because every place that appends to the list
(cfgparse-listen.c, proxy.c, tcp_rules.c and http_act.c) does "hdr->next = px->
req_cap; hdr->index = px->nb_req_cap++; px->req_cap = hdr;", so the head always
carries the highest index and the walk keeps hdr->index == i. But relying on
that invariant to index an array while the neighbouring lines use the field that
actually describes the slot is confusing, and it silently ties these two
functions to the way the list happens to be built.

Let's use hdr->index everywhere. No functional change.
src/http_conv.c