]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: buffers: make buffer_pointer() support negative pointers too
authorWilly Tarreau <w@1wt.eu>
Mon, 28 Nov 2011 15:04:29 +0000 (16:04 +0100)
committerWilly Tarreau <w@1wt.eu>
Mon, 28 Nov 2011 20:00:46 +0000 (21:00 +0100)
It's more handy if the buffer_pointer() function also handles negative pointers.

include/proto/buffers.h

index 0a2da34984cc94e99c7fa74d17f22c6be0753106..0d395a077346079fc34c272d1844ac302f86087e 100644 (file)
@@ -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
  * 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
- * 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.
  */
 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;
        return ptr;
 }