]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: buffer: make bo_getblk_nc() not return 2 for a full buffer
authorWilly Tarreau <w@1wt.eu>
Fri, 20 Oct 2017 16:21:49 +0000 (18:21 +0200)
committerWilly Tarreau <w@1wt.eu>
Sun, 22 Oct 2017 07:54:12 +0000 (09:54 +0200)
Thus function returns the number of blocks. When a buffer is full and
properly aligned, buf->p loops back the beginning, and the test in the
code doesn't cover that specific case, so it returns two chunks, a full
one and an empty one. It's harmless but can sometimes have a small impact
on performance and definitely makes the code hard to debug.

include/common/buffer.h

index 5ebf18cb3562af6a9f29fb32bc118bb8dad0e72d..9006c0095350184813b6d3ba4608ca3aa50f0dc6 100644 (file)
@@ -532,7 +532,7 @@ static inline int bo_getblk_nc(struct buffer *buf, char **blk1, int *len1, char
        if (unlikely(buf->o == 0))
                return 0;
 
-       if (unlikely(buf->p - buf->o < buf->data)) {
+       if (unlikely(buf->p != buf->data && buf->p - buf->o < buf->data)) {
                *blk1 = buf->p - buf->o + buf->size;
                *len1 = buf->data + buf->size - *blk1;
                *blk2 = buf->data;