Fixed core dump in HuffmanEncoder::GenerateCodeLengths in case of only one leaf in tree.

pull/242/head
Anton Gorev 2016-08-10 14:40:55 -05:00
parent 90f9d1a9db
commit 099811eda0
1 changed files with 9 additions and 0 deletions

View File

@ -126,6 +126,15 @@ void HuffmanEncoder::GenerateCodeLengths(unsigned int *codeBits, unsigned int ma
std::fill(codeBits, codeBits+nCodes, 0);
return;
}
if (1 == nCodes - treeBegin)
{
// special case when only one leaf in tree
fill(codeBits, codeBits + nCodes, 0);
codeBits[tree[treeBegin].symbol] = 1;
return;
}
tree.resize(nCodes + nCodes - treeBegin - 1);
size_t leastLeaf = treeBegin, leastInterior = nCodes;