X-Git-Url: https://diplodocus.org/git/nmh/blobdiff_plain/17ce15185fd5251a4fe8cec02950f0246d891e20..079b426e4e813191dedbf8ba4aa454adf2f0a46d:/sbr/base64.c?ds=inline diff --git a/sbr/base64.c b/sbr/base64.c index 7ceb27b9..2fbef4b0 100644 --- a/sbr/base64.c +++ b/sbr/base64.c @@ -48,7 +48,15 @@ writeBase64aux (FILE *in, FILE *out, int crlf) * everything down and push the last character back. */ if (i == cc - 1) { - ungetc('\n', in); + /* + * If we're at the end of the input, there might be + * more room in inbuf; if so, add it there. Otherwise + * push it back to the input. + */ + if (cc < sizeof(inbuf)) + inbuf[cc++] = '\n'; + else + ungetc('\n', in); skipnl = 1; } else { /* This only works as long as sizeof(inbuf) == 3 */