From 3b88d27e80dfc8482a41d1f59e2b850256582bc4 Mon Sep 17 00:00:00 2001 From: David Woodhouse Date: Wed, 19 May 2021 09:32:41 +0100 Subject: [PATCH] Fix first line length in buf_append_base64() We need to add four (for the characters we're about to append) *after* checking against line_len and resetting ll to zero. Otherwise the first line thinks it starts at 4 while the others start at 0. Signed-off-by: David Woodhouse --- textbuf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/textbuf.c b/textbuf.c index dc9a32e5..a8b22a48 100644 --- a/textbuf.c +++ b/textbuf.c @@ -438,11 +438,11 @@ void buf_append_base64(struct oc_text_buf *buf, const void *bytes, int len, int ll = 0; while (len > 0) { if (line_len) { - ll += 4; if (ll >= line_len) { ll = 0; buf->data[buf->pos++] = '\n'; } + ll += 4; } buf->data[buf->pos++] = b64_table[in[0] >> 2]; -- 2.49.0