about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2022-02-20 12:24:54 -0500
committerJune McEnroe <june@causal.agency>2022-02-20 12:24:54 -0500
commit8065fcabc35006c55b42a8771fa7cdedf4f31a8d (patch)
tree2c4ad55d0a0bf774869ed694320ae387674ce2f1
parentRemove unused mbs.len field from struct Edit (diff)
downloadcatgirl-8065fcabc35006c55b42a8771fa7cdedf4f31a8d.tar.gz
catgirl-8065fcabc35006c55b42a8771fa7cdedf4f31a8d.zip
Make sure new cap is actually larger than new length
Diffstat (limited to '')
-rw-r--r--edit.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/edit.c b/edit.c
index b0bdb23..a8f5d4a 100644
--- a/edit.c
+++ b/edit.c
@@ -75,7 +75,8 @@ int editReserve(struct Edit *e, size_t index, size_t count) {
 		return -1;
 	}
 	if (e->len + count > e->cap) {
-		size_t cap = (e->cap ? e->cap * 2 : 256);
+		size_t cap = (e->cap ?: 256);
+		while (cap < e->len + count) cap *= 2;
 		wchar_t *buf = realloc(e->buf, sizeof(*buf) * cap);
 		if (!buf) return -1;
 		e->buf = buf;