From fe4b1f9dc03f1c62dd9d45f18d99cf9d9919e11f Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Mon, 28 Nov 2011 13:40:49 +0100 Subject: BUG: buffers: don't return a negative value on buffer_total_space_res() In commit 4b517ca93aaaead8aa6143aa2836dc96417653c6 (MEDIUM: buffers: add some new primitives and rework existing ones), we forgot to check if buffer_max_len() < l. No backport is needed. --- include/proto/buffers.h | 6 ++++-- 1 files changed, 4 insertions(+), 2 deletions(-) diff --git a/include/proto/buffers.h b/include/proto/buffers.h index b241a56..0a2da34 100644 --- a/include/proto/buffers.h +++ b/include/proto/buffers.h @@ -103,11 +103,13 @@ static inline int buffer_total_space(const struct buffer *buf) } /* Return the maximum amount of bytes that can be written into the buffer, - * excluding the reserved space, which is preserved. + * excluding the reserved space, which is preserved. 0 may be returned if + * the reserved space was already reached or used. */ static inline int buffer_total_space_res(const struct buffer *buf) { - return buffer_max_len(buf) - buf->l; + int len = buffer_max_len(buf) - buf->l; + return len < 0 ? 0 : len; } /* Returns the number of contiguous bytes between and +, -- 1.7.2.3