vis

a vi-like editor based on Plan 9's structural regular expressions

git clone https://9o.is/git/vis.git

commit 8855c7e1f6c2a816459ff173e16ec8b71b048eb4
parent 14c57210a66fc3a71bbb0e3ff42598c6e4267c0c
Author: Marc André Tanner <mat@brain-dump.org>
Date:   Tue, 20 Dec 2016 18:59:44 +0100

buffer: fix error case in buffer_append0

Do not change buffer length when failing to append.

Diffstat:
Mbuffer.c | 9++++++---
1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/buffer.c b/buffer.c @@ -93,9 +93,12 @@ bool buffer_append(Buffer *buf, const void *data, size_t len) { } bool buffer_append0(Buffer *buf, const char *data) { - if (buf->len > 0 && buf->data[buf->len-1] == '\0') - buf->len--; - return buffer_append(buf, data, strlen(data)) && buffer_append(buf, "\0", 1); + size_t nul = (buf->len > 0 && buf->data[buf->len-1] == '\0') ? 1 : 0; + buf->len -= nul; + bool ret = buffer_append(buf, data, strlen(data)+1); + if (!ret) + buf->len += nul; + return ret; } bool buffer_prepend(Buffer *buf, const void *data, size_t len) {