LibGfx/WebPWriter: Do not convert -inf to unsigned

Else UBSan complains about the color indexing test in this PR.
This commit is contained in:
Nico Weber 2024-05-31 15:50:41 -04:00 committed by Jelle Raaijmakers
parent 9e61912f64
commit 47d3245ea7
Notes: sideshowbarker 2024-07-17 04:32:07 +09:00

View file

@ -206,7 +206,7 @@ static ErrorOr<CanonicalCode> write_normal_code_lengths(LittleEndianOutputBitStr
// "int length_nbits = 2 + 2 * ReadBits(3);
// int max_symbol = 2 + ReadBits(length_nbits);"
// => length_nbits is at most 2 + 2*7 == 16
unsigned needed_length_nbits = floor(log2(encoded_lengths_count - 2) + 1);
unsigned needed_length_nbits = encoded_lengths_count > 2 ? floor(log2(encoded_lengths_count - 2) + 1) : 2;
VERIFY(needed_length_nbits <= 16);
needed_length_nbits = ceil_div(needed_length_nbits, 2) * 2;
TRY(bit_stream.write_bits((needed_length_nbits - 2) / 2, 3u));