]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
Fixed : compression error on some specific distribution
authorYann Collet <yann.collet.73@gmail.com>
Tue, 25 Aug 2015 21:56:42 +0000 (22:56 +0100)
committerYann Collet <yann.collet.73@gmail.com>
Tue, 25 Aug 2015 21:56:42 +0000 (22:56 +0100)
lib/fse.c

index 2c55a5635caf7a60821fdd505be36daf202748dd..be3919f45badf91c0d03c1bb0433b46816420b5c 100644 (file)
--- 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 */
                                {