Skip to content

Commit

Permalink
buffer: make sure mem{cpy,move} are called with valid arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
martanne committed Jan 7, 2017
1 parent 2c22684 commit f9bdb35
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit f9bdb35

Please sign in to comment.