buf.c: fix off by one bug in buf_add_char()

Written-by: @johanmalm

Fixes: #2313

Backported from 7e50c60b00
This commit is contained in:
Johan Malm 2024-11-07 21:08:09 +00:00 committed by Consolatis
parent 6fe3c97443
commit 6c05316f55

View file

@ -111,7 +111,7 @@ buf_add(struct buf *s, const char *data)
void
buf_add_char(struct buf *s, char ch)
{
buf_expand(s, s->len + 1);
buf_expand(s, s->len + 2);
s->data[s->len++] = ch;
s->data[s->len] = '\0';
}