vis
a vi-like editor based on Plan 9's structural regular expressions
git clone https://9o.is/git/vis.git
commit 62dd689085155ffbdd918652a9252faf7e89a3a2 parent 381c17ed7598b19d969a031c6fd59c3ba8f3cf1a Author: Marc André Tanner <mat@brain-dump.org> Date: Tue, 31 Mar 2015 10:42:21 +0200 Check return value of realloc Diffstat:
| M | buffer.c | | | 8 | +++----- |
1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/buffer.c b/buffer.c @@ -12,13 +12,11 @@ bool buffer_alloc(Buffer *buf, size_t size) { if (buf->size < size) { if (buf->size > 0) size *= 2; - buf->data = realloc(buf->data, size); - if (!buf->data) { - buf->size = 0; - buf->len = 0; + char *data = realloc(buf->data, size); + if (!data) return false; - } buf->size = size; + buf->data = data; } return true; }