We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 392088a commit 865a992Copy full SHA for 865a992
zlib-rs/src/inflate/inftrees.rs
@@ -77,16 +77,12 @@ pub(crate) fn inflate_table(
77
let root = bits.clamp(min, max);
78
79
/* check for an over-subscribed or incomplete set of lengths */
80
- let mut left = 1i32;
81
- let mut len = 1;
82
- while len <= MAX_BITS {
83
- left <<= 1;
84
- left -= count[len] as i32;
85
- if left < 0 {
86
- // over-subscribed
87
- return InflateTable::InvalidCode;
88
- }
89
- len += 1;
+ let mut left = 1u32;
+ for &sym in &count[1..] {
+ left = match (left << 1).checked_sub(u32::from(sym)) {
+ None => return InflateTable::InvalidCode, // over-subscribed
+ Some(v) => v,
+ };
90
}
91
92
if left > 0 && (matches!(codetype, CodeType::Codes) || max != 1) {
0 commit comments