From: Yann Collet Date: Tue, 25 Aug 2015 21:56:42 +0000 (+0100) Subject: Fixed : compression error on some specific distribution X-Git-Tag: v0.1.1^2~7 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c7055675225e9d67e4094019d58eabe9275acd97;p=thirdparty%2Fzstd.git Fixed : compression error on some specific distribution --- diff --git a/lib/fse.c b/lib/fse.c index 2c55a5635..be3919f45 100644 --- a/lib/fse.c +++ b/lib/fse.c @@ -1904,11 +1904,17 @@ static U32 HUF_setMaxHeight(nodeElt* huffNode, U32 lastNonNull, U32 maxNbBits) if (rankLast[nBitsToDecrease-1] == noOne) rankLast[nBitsToDecrease-1] = rankLast[nBitsToDecrease]; // now there is one elt huffNode[rankLast[nBitsToDecrease]].nbBits ++; - rankLast[nBitsToDecrease]--; - if (huffNode[rankLast[nBitsToDecrease]].nbBits != maxNbBits-nBitsToDecrease) - rankLast[nBitsToDecrease] = noOne; // rank list emptied + if (rankLast[nBitsToDecrease] > 0) + { + rankLast[nBitsToDecrease]--; + if (huffNode[rankLast[nBitsToDecrease]].nbBits != maxNbBits-nBitsToDecrease) + rankLast[nBitsToDecrease] = noOne; // rank list emptied + } + else + rankLast[nBitsToDecrease] = noOne; // rank list emptied } - while (totalCost < 0) // Sometimes, cost correction overshoot + + while (totalCost < 0) /* Sometimes, cost correction overshoot */ { if (rankLast[1] == noOne) /* special case, no weight 1, let's find it back at n */ {