From 8065fcabc35006c55b42a8771fa7cdedf4f31a8d Mon Sep 17 00:00:00 2001 From: June McEnroe Date: Sun, 20 Feb 2022 12:24:54 -0500 Subject: Make sure new cap is actually larger than new length --- edit.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'edit.c') 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; -- cgit 1.4.1-2-gfad0