From: Amaury Denoyelle Date: Thu, 19 Nov 2026 09:49:41 +0000 (+0100) Subject: CLEANUP/MINOR: ncbuf: avoid noop memcpy when data ends on wrapping X-Git-Url: https://git.kaiwu.me/http/%7B@url%7D?a=commitdiff_plain;h=900b7b952c74655d6a4170eb9a26f7370d32631f;p=haproxy.git CLEANUP/MINOR: ncbuf: avoid noop memcpy when data ends on wrapping The ncbuf add operation implements support for wrapping in case the newly inserted data exceeds the buffer end. This operation is inefficient due to an excessive comparison, in case the data just ends at the buffer boundary. Two memcpy are used, the second one with a 0 length argument which is a noop. Change the comparison to greater-than to select the single memcpy path. The main objective of this patch is to clean up wrapping comparison and avoid future incorrect code duplication. --- diff --git a/src/ncbuf.c b/src/ncbuf.c index e1452f1d2..430d8fced 100644 --- a/src/ncbuf.c +++ b/src/ncbuf.c @@ -313,7 +313,7 @@ static ncb_sz_t ncb_fill_data_blk(const struct ncbuf *buf, if (mode == NCB_ADD_OVERWRT) { ptr = ncb_peek(buf, blk->off + off); - if (ptr + to_copy >= ncb_wrap(buf)) { + if (ptr + to_copy > ncb_wrap(buf)) { const ncb_sz_t sz1 = ncb_wrap(buf) - ptr; memcpy(ptr, data, sz1); memcpy(ncb_orig(buf), data + sz1, to_copy - sz1); @@ -363,7 +363,7 @@ static ncb_sz_t ncb_fill_gap_blk(const struct ncbuf *buf, /* fill the gap with new data */ ptr = ncb_peek(buf, blk->off + off); - if (ptr + to_copy >= ncb_wrap(buf)) { + if (ptr + to_copy > ncb_wrap(buf)) { ncb_sz_t sz1 = ncb_wrap(buf) - ptr; memcpy(ptr, data, sz1); memcpy(ncb_orig(buf), data + sz1, to_copy - sz1);