fix bug to allow base32 coding

pull/2/head
weidai 2003-01-16 00:47:48 +00:00
parent 59b93d575e
commit 8da70ac4e0
1 changed files with 23 additions and 8 deletions

View File

@ -41,17 +41,32 @@ unsigned int BaseN_Encoder::Put2(const byte *begin, unsigned int length, int mes
if (m_bytePos == 0) if (m_bytePos == 0)
memset(m_outBuf, 0, m_outputBlockSize); memset(m_outBuf, 0, m_outputBlockSize);
m_outBuf[m_bytePos] |= begin[m_inputPosition] >> (8-m_bitsPerChar+m_bitPos);
m_outBuf[m_bytePos+1] |= ((begin[m_inputPosition] << (m_bitsPerChar-m_bitPos)) & 0xff) >> (8-m_bitsPerChar);
++m_inputPosition;
m_bitPos += 8;
while (m_bitPos >= m_bitsPerChar)
{ {
m_bitPos -= m_bitsPerChar; unsigned int b = begin[m_inputPosition++], bitsLeftInSource = 8;
++m_bytePos; while (true)
{
assert(m_bitPos < m_bitsPerChar);
unsigned int bitsLeftInTarget = m_bitsPerChar-m_bitPos;
m_outBuf[m_bytePos] |= b >> (8-bitsLeftInTarget);
if (bitsLeftInSource >= bitsLeftInTarget)
{
m_bitPos = 0;
++m_bytePos;
bitsLeftInSource -= bitsLeftInTarget;
if (bitsLeftInSource == 0)
break;
b <<= bitsLeftInTarget;
b &= 0xff;
}
else
{
m_bitPos += bitsLeftInSource;
break;
}
}
} }
assert(m_bytePos <= m_outputBlockSize);
if (m_bytePos == m_outputBlockSize) if (m_bytePos == m_outputBlockSize)
{ {
int i; int i;