mirror of
http://git.haproxy.org/git/haproxy.git/
synced 2025-02-03 12:03:02 +00:00
BUG/MINOR: buffers: Fix bi/bo_contig_space to handle full buffers
These functions was added in commit 637f8f2c
("BUG/MEDIUM: buffers: Fix how
input/output data are injected into buffers").
This patch fixes hidden bugs. When a buffer is full (buf->i + buf->o ==
buf->size), instead of returning 0, these functions can return buf->size. Today,
this never happens because callers already check if the buffer is full before
calling bi/bo_contig_space. But to avoid possible bugs if calling conditions
changed, we slightly refactored these functions.
This commit is contained in:
parent
6a0bca9e78
commit
a36b311b9f
@ -163,12 +163,16 @@ static inline int bi_contig_space(const struct buffer *b)
|
|||||||
{
|
{
|
||||||
const char *left, *right;
|
const char *left, *right;
|
||||||
|
|
||||||
left = bi_end(b);
|
left = b->p + b->i;
|
||||||
right = bo_ptr(b);
|
right = b->p - b->o;
|
||||||
|
if (left >= b->data + b->size)
|
||||||
if (left >= right)
|
left -= b->size;
|
||||||
right = b->data + b->size;
|
else {
|
||||||
|
if (right < b->data)
|
||||||
|
right += b->size;
|
||||||
|
else
|
||||||
|
right = b->data + b->size;
|
||||||
|
}
|
||||||
return (right - left);
|
return (right - left);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -181,10 +185,11 @@ static inline int bo_contig_space(const struct buffer *b)
|
|||||||
{
|
{
|
||||||
const char *left, *right;
|
const char *left, *right;
|
||||||
|
|
||||||
left = bo_end(b);
|
left = b->p;
|
||||||
right = bo_ptr(b);
|
right = b->p - b->o;
|
||||||
|
if (right < b->data)
|
||||||
if (left >= right)
|
right += b->size;
|
||||||
|
else
|
||||||
right = b->data + b->size;
|
right = b->data + b->size;
|
||||||
|
|
||||||
return (right - left);
|
return (right - left);
|
||||||
|
Loading…
Reference in New Issue
Block a user