Make sure new cap is actually larger than new length

weechat-hashes
June McEnroe 2022-02-20 12:24:54 -05:00
parent 157be8a8d7
commit 8065fcabc3
1 changed files with 2 additions and 1 deletions

3
edit.c
View File

@ -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;