fix: Buffer capacity calculation for encode
1 files changed, 3 insertions(+), 2 deletions(-) M src/baseenc.c
M src/baseenc.c +3 -2
@@ 10,10 10,11 @@ static Janet Baseenc_base64Encode(int ar if (argc > 1) { buf = janet_getbuffer(argv, 1); } else { - buf = janet_buffer((data.len * 4 + 3) / 3); + buf = janet_buffer((data.len + 2) / 3 * 4); } - ssize_t len = base_64_encode(&data.bytes[0], (size_t)data.len, &buf->data[0], (size_t)buf->capacity); + ssize_t len = base_64_encode(&data.bytes[0], (size_t)data.len, + &buf->data[0], (size_t)buf->capacity); if (len == -1) { janet_panic("buffer overflow"); }