From 8f7a3ab27a3393de7d475e67d09ab1b82eaa8013 Mon Sep 17 00:00:00 2001 From: Vincent Richard Date: Fri, 17 Nov 2006 22:57:48 +0000 Subject: [PATCH] Fixed maximum line length bug. --- src/encoderB64.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/encoderB64.cpp b/src/encoderB64.cpp index 8ef788b6..0e8bbe30 100644 --- a/src/encoderB64.cpp +++ b/src/encoderB64.cpp @@ -117,13 +117,16 @@ const utility::stream::size_type encoderB64::encode(utility::inputStream& in, while (count < 3 && bufferPos < bufferLength) bytes[count++] = buffer[bufferPos++]; - if (count != 3) + while (count < 3) { // There may be more data in the next chunk... if (bufferPos >= bufferLength) { bufferLength = in.read(buffer, sizeof(buffer)); bufferPos = 0; + + if (bufferLength == 0) + break; } while (count < 3 && bufferPos < bufferLength) @@ -169,7 +172,7 @@ const utility::stream::size_type encoderB64::encode(utility::inputStream& in, total += 4; curCol += 4; - if (cutLines && curCol >= maxLineLength - 1) + if (cutLines && curCol >= maxLineLength - 2 /* \r\n */ - 4 /* next bytes */) { out.write("\r\n", 2); curCol = 0;