mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-09-23 06:41:32 +02:00
MINOR: buffers: make buffer_pointer() support negative pointers too
It's more handy if the buffer_pointer() function also handles negative pointers.
This commit is contained in:
parent
fe4b1f9dc0
commit
71730256a3
@ -186,12 +186,14 @@ static inline int buffer_contig_space_with_res(struct buffer *buf, int res)
|
|||||||
/* Normalizes a pointer which is supposed to be relative to the beginning of a
|
/* Normalizes a pointer which is supposed to be relative to the beginning of a
|
||||||
* buffer, so that wrapping is correctly handled. The intent is to use this
|
* buffer, so that wrapping is correctly handled. The intent is to use this
|
||||||
* when increasing a pointer. Note that the wrapping test is only performed
|
* when increasing a pointer. Note that the wrapping test is only performed
|
||||||
* once, so the original pointer must be between ->data and ->data+2*size - 1,
|
* once, so the original pointer must be between ->data-size and ->data+2*size-1,
|
||||||
* otherwise an invalid pointer might be returned.
|
* otherwise an invalid pointer might be returned.
|
||||||
*/
|
*/
|
||||||
static inline char *buffer_pointer(const struct buffer *buf, char *ptr)
|
static inline char *buffer_pointer(const struct buffer *buf, char *ptr)
|
||||||
{
|
{
|
||||||
if (ptr - buf->size >= buf->data)
|
if (ptr < buf->data)
|
||||||
|
ptr += buf->size;
|
||||||
|
else if (ptr - buf->size >= buf->data)
|
||||||
ptr -= buf->size;
|
ptr -= buf->size;
|
||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user