Commit 2b85c12f authored by Martin Blix Grydeland's avatar Martin Blix Grydeland

Fix buffer underflow in _vsb_indent

If s_indent > 0 and the buffer is empty, it would check s_buf[-1] for
the '\n' character.

Now it will indent either on previous character being a newline, or on
empty buffer. This allows indenting also the very first line of a
buffer.
parent 2223ff49
......@@ -159,7 +159,7 @@ static void
_vsb_indent(struct vsb *s)
{
if (s->s_indent == 0 || s->s_error != 0 ||
s->s_buf[s->s_len - 1] != '\n')
(s->s_len > 0 && s->s_buf[s->s_len - 1] != '\n'))
return;
if (VSB_FREESPACE(s) <= s->s_indent &&
VSB_extend(s, s->s_indent) < 0) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment