fix bug to allow base32 coding
parent
59b93d575e
commit
8da70ac4e0
29
basecode.cpp
29
basecode.cpp
|
|
@ -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;
|
||||||
|
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;
|
++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;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue