From f9bdb3515d20fa9d11452fb68c761388b01e1251 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Andr=C3=A9=20Tanner?= Date: Sat, 7 Jan 2017 13:18:05 +0100 Subject: [PATCH] buffer: make sure mem{cpy,move} are called with valid arguments --- buffer.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/buffer.c b/buffer.c index 94c074e03..3bc89d244 100644 --- a/buffer.c +++ b/buffer.c @@ -70,9 +70,13 @@ bool buffer_remove(Buffer *buf, size_t pos, size_t len) { bool buffer_insert(Buffer *buf, size_t pos, const void *data, size_t len) { if (pos > buf->len) return false; + if (len == 0) + return true; if (!buffer_grow(buf, buf->len + len)) return false; - memmove(buf->data + pos + len, buf->data + pos, buf->len - pos); + size_t move = buf->len - pos; + if (move > 0) + memmove(buf->data + pos + len, buf->data + pos, move); memcpy(buf->data + pos, data, len); buf->len += len; return true;