Skip to content

Commit 041713f

Browse files
committed
Fix again commit 63fdd08
1 parent 32be3e9 commit 041713f

2 files changed

Lines changed: 11 additions & 8 deletions

File tree

src/entropy/HuffmanDecoder.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -337,10 +337,10 @@ bool HuffmanDecoder::decodeChunk(kanzi::byte block[], uint count)
337337
for (uint i = count4; i < count; i++)
338338
block[i] = kanzi::byte(_bitstream.readBits(8));
339339

340-
const int used0 = ((idx0 - base0) << 3) - (bits0 + DECODING_BATCH_SIZE);
341-
const int used1 = ((idx1 - base1) << 3) - (bits1 + DECODING_BATCH_SIZE);
342-
const int used2 = ((idx2 - base2) << 3) - (bits2 + DECODING_BATCH_SIZE);
343-
const int used3 = ((idx3 - base3) << 3) - (bits3 + DECODING_BATCH_SIZE);
340+
const int used0 = ((idx0 - base0) << 3) - (int(int8(bits0)) + DECODING_BATCH_SIZE);
341+
const int used1 = ((idx1 - base1) << 3) - (int(int8(bits1)) + DECODING_BATCH_SIZE);
342+
const int used2 = ((idx2 - base2) << 3) - (int(int8(bits2)) + DECODING_BATCH_SIZE);
343+
const int used3 = ((idx3 - base3) << 3) - (int(int8(bits3)) + DECODING_BATCH_SIZE);
344344

345345
return (used0 == szBits0) && (used1 == szBits1) &&
346346
(used2 == szBits2) && (used3 == szBits3);
@@ -448,7 +448,7 @@ int HuffmanDecoder::decodeV5(kanzi::byte block[], uint blkptr, uint count)
448448
block[n++] = kanzi::byte(val >> 8);
449449
}
450450

451-
if (((idx << 3) - int(bits)) != szBits)
451+
if (((idx << 3) - int(int8(bits))) != szBits)
452452
return -1;
453453
}
454454

src/test/TestEntropyCodec.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -310,14 +310,17 @@ int testHuffmanFragmentedRoundTrip()
310310
{
311311
cout << endl
312312
<< "=== Huffman fragmented round-trip test ===" << endl;
313-
const uint size = 1 << 20;
313+
const uint size = 1649;
314314
vector<kanzi::byte> values(size);
315315
vector<kanzi::byte> decoded(size, kanzi::byte(0));
316-
uint32 state = 0x12345678;
316+
uint32 state = 3454687338U;
317317

318318
for (uint i = 0; i < size; i++) {
319319
state = (state * 1103515245U) + 12345U;
320-
values[i] = kanzi::byte(state >> 24);
320+
const uint32 val0 = state >> 24;
321+
state = (state * 1103515245U) + 12345U;
322+
const uint32 val1 = state >> 24;
323+
values[i] = (val0 < 192) ? kanzi::byte(val1 & 15) : kanzi::byte(val1);
321324
}
322325

323326
stringbuf buffer;

0 commit comments

Comments
 (0)