(fix) unsafe array access in skipf and skipb

skipf was accessed at index 81 (len only 81)
skipb was accessed at index -1 (u64::MAX)

I still don't know, why the skipb case didn't crash.
This commit is contained in:
ddidderr 2023-06-16 16:57:25 +02:00
parent e446d9b74f
commit fc9fc1a048
Signed by: ddidderr
GPG Key ID: 3841F1C27E6F0E14

View File

@ -51,7 +51,7 @@ impl SField {
fixed_count
}
let mut skipf = vec![0; NUM_FIELDS];
let mut skipf = vec![0; NUM_FIELDS + 1];
for (idx, nr) in field.iter().enumerate() {
match nr {
0 => skipf[idx] = *nr,
@ -59,11 +59,11 @@ impl SField {
}
}
let mut skipb = vec![0; NUM_FIELDS];
let mut skipb = vec![0; NUM_FIELDS + 1];
for (idx, nr) in field.iter().enumerate().rev() {
match nr {
0 => skipb[idx] = *nr,
_ => skipb[idx] = find_fixed_streak_backward(idx, &field),
0 => skipb[idx + 1] = *nr,
_ => skipb[idx + 1] = find_fixed_streak_backward(idx, &field),
}
}
@ -257,7 +257,7 @@ impl SField {
}
fn prev(&mut self) -> bool {
let new_pos = self.pos - 1 - unsafe { *self.skipb.get_unchecked(self.pos - 1) as usize };
let new_pos = self.pos - 1 - unsafe { *self.skipb.get_unchecked(self.pos) as usize };
if new_pos >= NUM_FIELDS {
return false;