mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-04 13:30:31 +00:00
LibCompress: Use saturating add in generate_huffman_lengths()
For our deflate, block size is limited to less than 64 kiB, so the sum of all byte frequencies always fits in a u16 by construction. But while I haven't hit this in practice, but it can conceivably happen when writing WebP files, which currently use a single huffman tree (per channel) for a while image -- which is often much larger than 64 kiB. No dramatic behavior change in practice, just feels more correct.
This commit is contained in:
parent
0711e9d749
commit
2023e8d8d9
Notes:
sideshowbarker
2024-07-16 22:17:03 +09:00
Author: https://github.com/nico Commit: https://github.com/SerenityOS/serenity/commit/2023e8d8d9 Pull-request: https://github.com/SerenityOS/serenity/pull/24454
1 changed files with 3 additions and 1 deletions
|
@ -53,7 +53,9 @@ void generate_huffman_lengths(Array<u8, Size>& lengths, Array<u16, Size> const&
|
|||
|
||||
u16 new_link = heap.size() + 1;
|
||||
|
||||
heap.insert(lowest_frequency + second_lowest_frequency, new_link);
|
||||
u32 sum = lowest_frequency + second_lowest_frequency;
|
||||
sum = min(sum, UINT16_MAX);
|
||||
heap.insert(sum, new_link);
|
||||
|
||||
huffman_links[lowest_link] = new_link;
|
||||
huffman_links[second_lowest_link] = new_link;
|
||||
|
|
Loading…
Reference in a new issue