From 64e491e688289a755518ef2b7613910809d9fb83 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Wed, 28 Oct 2015 01:35:05 +0100 Subject: [PATCH] Fixed issue #52 (faulty binary generation with Visual Studio 2013 & 2015 in release mode (compiler bug)), reported and fixed by Christophe Chevalier (@KrzysFR) --- lib/huff0.c | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/lib/huff0.c b/lib/huff0.c index 74c7a7be..72b12bdf 100644 --- a/lib/huff0.c +++ b/lib/huff0.c @@ -1017,24 +1017,29 @@ size_t HUF_readDTableX4 (U32* DTable, const void* src, size_t srcSize) rankStart[0] = 0; /* forget 0w symbols; this is beginning of weight(1) */ } - /* Build rankVal */ + /* Build rankVal */ { const U32 minBits = tableLog+1 - maxW; U32 nextRankVal = 0; U32 w, consumed; const int rescale = (memLog-tableLog) - 1; /* tableLog <= memLog */ + U32* rankVal0 = rankVal[0]; for (w=1; w<=maxW; w++) { U32 current = nextRankVal; nextRankVal += rankStats[w] << (w+rescale); - rankVal[0][w] = current; + rankVal0[w] = current; + } + for (consumed = minBits; consumed <= memLog - minBits; consumed++) + { + U32* rankValPtr = rankVal[consumed]; + for (w = 1; w <= maxW; w++) + { + rankValPtr[w] = rankVal0[w] >> consumed; + } } - for (consumed=minBits; consumed <= memLog-minBits; consumed++) - for (w=1; w<=maxW; w++) - rankVal[consumed][w] = rankVal[0][w] >> consumed; } - HUF_fillDTableX4(dt, memLog, sortedSymbol, sizeOfSort, rankStart0, rankVal, maxW, @@ -1384,21 +1389,27 @@ size_t HUF_readDTableX6 (U32* DTable, const void* src, size_t srcSize) rankStart[0] = 0; /* forget 0w symbols; this is beginning of weight(1) */ } - /* Build rankVal */ + /* Build rankVal */ { const U32 minBits = tableLog+1 - maxW; U32 nextRankVal = 0; U32 w, consumed; const int rescale = (memLog-tableLog) - 1; /* tableLog <= memLog */ + U32* rankVal0 = rankVal[0]; for (w=1; w<=maxW; w++) { U32 current = nextRankVal; nextRankVal += rankStats[w] << (w+rescale); - rankVal[0][w] = current; + rankVal0[w] = current; + } + for (consumed = minBits; consumed <= memLog - minBits; consumed++) + { + U32* rankValPtr = rankVal[consumed]; + for (w = 1; w <= maxW; w++) + { + rankValPtr[w] = rankVal0[w] >> consumed; + } } - for (consumed=minBits; consumed <= memLog-minBits; consumed++) - for (w=1; w<=maxW; w++) - rankVal[consumed][w] = rankVal[0][w] >> consumed; }