-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove double bounds check #77
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -213,25 +213,24 @@ | |
($s:expr) => { | ||
if groupPos == 0 { | ||
groupNo += 1; | ||
if groupNo >= nSelectors as i32 { | ||
error!(BZ_DATA_ERROR); | ||
} else { | ||
groupPos = 50; | ||
gSel = $s.selector[groupNo as usize]; | ||
gLimit = gSel; | ||
gPerm = gSel; | ||
gBase = gSel; | ||
gMinlen = $s.minLens[gSel as usize]; | ||
} | ||
gSel = match $s.selector[..usize::from(nSelectors)].get(groupNo as usize) { | ||
Some(&gSel) => gSel, | ||
None => error!(BZ_DATA_ERROR), | ||
}; | ||
gLimit = gSel; | ||
gPerm = gSel; | ||
gBase = gSel; | ||
gMinlen = $s.minLens[gSel as usize]; | ||
groupPos = 50; | ||
} | ||
groupPos -= 1; | ||
}; | ||
} | ||
|
||
macro_rules! error { | ||
($code:ident) => { | ||
($code:ident) => {{ | ||
break 'save_state_and_return ReturnCode::$code; | ||
}; | ||
}}; | ||
} | ||
|
||
match s.state { | ||
|
@@ -356,14 +355,11 @@ | |
|
||
uc = GET_BYTE!(strm, s); | ||
|
||
if uc == 0x17 { | ||
// skips to `State::BZ_X_ENDHDR_2` | ||
current_block = BZ_X_ENDHDR_2; | ||
} else if uc != 0x31 { | ||
error!(BZ_DATA_ERROR); | ||
} else { | ||
current_block = BZ_X_BLKHDR_2; | ||
} | ||
match uc { | ||
0x17 => current_block = BZ_X_ENDHDR_2, | ||
0x31 => current_block = BZ_X_BLKHDR_2, | ||
_ => error!(BZ_DATA_ERROR), | ||
}; | ||
} | ||
match current_block { | ||
BZ_X_ENDHDR_2 => { | ||
|
@@ -768,12 +764,11 @@ | |
if zn > 20 { | ||
error!(BZ_DATA_ERROR); | ||
} else if zvec <= s.limit[gLimit as usize][zn as usize] { | ||
if !(0..258).contains(&(zvec - s.base[gBase as usize][zn as usize])) { | ||
error!(BZ_DATA_ERROR); | ||
} else { | ||
nextSym = s.perm[gPerm as usize] | ||
[(zvec - s.base[gBase as usize][zn as usize]) as usize]; | ||
} | ||
let index = zvec - s.base[gBase as usize][zn as usize]; | ||
nextSym = match s.perm[gPerm as usize].get(index as usize) { | ||
Some(&nextSym) => nextSym, | ||
None => error!(BZ_DATA_ERROR), | ||
}; | ||
Comment on lines
+767
to
+771
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the |
||
} else { | ||
zn += 1; | ||
current_block = BZ_X_MTF_6; | ||
|
@@ -785,43 +780,42 @@ | |
if zn > 20 { | ||
error!(BZ_DATA_ERROR); | ||
} else if zvec <= s.limit[gLimit as usize][zn as usize] { | ||
if !(0..258).contains(&(zvec - s.base[gBase as usize][zn as usize])) { | ||
error!(BZ_DATA_ERROR); | ||
let index = zvec - s.base[gBase as usize][zn as usize]; | ||
nextSym = match s.perm[gPerm as usize].get(index as usize) { | ||
Some(&nextSym) => nextSym, | ||
None => error!(BZ_DATA_ERROR), | ||
}; | ||
if nextSym == BZ_RUNA as i32 || nextSym == BZ_RUNB as i32 { | ||
current_block = Block46; | ||
} else { | ||
nextSym = s.perm[gPerm as usize] | ||
[(zvec - s.base[gBase as usize][zn as usize]) as usize]; | ||
if nextSym == BZ_RUNA as i32 || nextSym == BZ_RUNB as i32 { | ||
current_block = Block46; | ||
} else { | ||
es += 1; | ||
uc = s.seqToUnseq[s.mtfa[s.mtfbase[0_usize] as usize] as usize]; | ||
s.unzftab[uc as usize] += es; | ||
match s.smallDecompress { | ||
DecompressMode::Small => { | ||
while es > 0 { | ||
if nblock >= 100000 * nblockMAX100k as u32 { | ||
error!(BZ_DATA_ERROR); | ||
} else { | ||
ll16[nblock as usize] = uc as u16; | ||
nblock += 1; | ||
es -= 1; | ||
} | ||
es += 1; | ||
uc = s.seqToUnseq[s.mtfa[s.mtfbase[0_usize] as usize] as usize]; | ||
s.unzftab[uc as usize] += es; | ||
match s.smallDecompress { | ||
DecompressMode::Small => { | ||
while es > 0 { | ||
if nblock >= 100000 * nblockMAX100k as u32 { | ||
error!(BZ_DATA_ERROR); | ||
} else { | ||
ll16[nblock as usize] = uc as u16; | ||
nblock += 1; | ||
es -= 1; | ||
} | ||
} | ||
DecompressMode::Fast => { | ||
while es > 0 { | ||
if nblock >= 100000 * nblockMAX100k as u32 { | ||
error!(BZ_DATA_ERROR); | ||
} else { | ||
tt[nblock as usize] = uc as u32; | ||
nblock += 1; | ||
es -= 1; | ||
} | ||
} | ||
DecompressMode::Fast => { | ||
while es > 0 { | ||
if nblock >= 100000 * nblockMAX100k as u32 { | ||
error!(BZ_DATA_ERROR); | ||
} else { | ||
tt[nblock as usize] = uc as u32; | ||
nblock += 1; | ||
es -= 1; | ||
} | ||
} | ||
} | ||
current_block = Block40; | ||
} | ||
current_block = Block40; | ||
} | ||
} else { | ||
zn += 1; | ||
|
@@ -833,12 +827,11 @@ | |
if zn > 20 { | ||
error!(BZ_DATA_ERROR); | ||
} else if zvec <= s.limit[gLimit as usize][zn as usize] { | ||
if !(0..258).contains(&(zvec - s.base[gBase as usize][zn as usize])) { | ||
error!(BZ_DATA_ERROR); | ||
} else { | ||
nextSym = s.perm[gPerm as usize] | ||
[(zvec - s.base[gBase as usize][zn as usize]) as usize]; | ||
} | ||
let index = zvec - s.base[gBase as usize][zn as usize]; | ||
nextSym = match s.perm[gPerm as usize].get(index as usize) { | ||
Some(&nextSym) => nextSym, | ||
None => error!(BZ_DATA_ERROR), | ||
}; | ||
} else { | ||
zn += 1; | ||
current_block = BZ_X_MTF_2; | ||
|
@@ -1285,8 +1278,6 @@ | |
|
||
EOB = s.nInUse + 1; | ||
nblockMAX100k = s.blockSize100k as u8; | ||
groupNo = -1; | ||
groupPos = 0; | ||
Comment on lines
-1288
to
-1289
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. moved over to hopefully make it clearer why |
||
s.unzftab.fill(0); | ||
|
||
/*-- MTF init --*/ | ||
|
@@ -1302,6 +1293,8 @@ | |
/*-- end MTF init --*/ | ||
|
||
nblock = 0; | ||
groupNo = -1; | ||
groupPos = 0; | ||
update_group_pos!(s); | ||
|
||
zn = gMinlen; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is just a cleanup that i spotted