diff options
| author | Marc André Tanner <mat@brain-dump.org> | 2017-01-07 13:18:05 +0100 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2017-01-07 13:43:23 +0100 |
| commit | f9bdb3515d20fa9d11452fb68c761388b01e1251 (patch) | |
| tree | f9eaaba7bd23c5853a159ff6614643a4017b5368 | |
| parent | 2c226842217f6260918496caa71ab03cc858e1d4 (diff) | |
| download | vis-f9bdb3515d20fa9d11452fb68c761388b01e1251.tar.gz vis-f9bdb3515d20fa9d11452fb68c761388b01e1251.tar.xz | |
buffer: make sure mem{cpy,move} are called with valid arguments
| -rw-r--r-- | buffer.c | 6 |
1 files changed, 5 insertions, 1 deletions
@@ -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; |
