vis
a vi-like editor based on Plan 9's structural regular expressions
git clone https://9o.is/git/vis.git
commit e2e324ac555cfa3e7ed764fc88aaf9eb9d4e6c73
parent 891f40bd8e57d77103364cd17ac9fb4dd326ef04
Author: Marc André Tanner <mat@brain-dump.org>
Date: Sat, 7 Jan 2017 13:18:05 +0100
buffer: make sure mem{cpy,move} are called with valid arguments
Diffstat:
| M | buffer.c | | | 6 | +++++- |
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git 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;