(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:
parent
e446d9b74f
commit
fc9fc1a048
10
src/main.rs
10
src/main.rs
@ -51,7 +51,7 @@ impl SField {
|
|||||||
fixed_count
|
fixed_count
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut skipf = vec![0; NUM_FIELDS];
|
let mut skipf = vec![0; NUM_FIELDS + 1];
|
||||||
for (idx, nr) in field.iter().enumerate() {
|
for (idx, nr) in field.iter().enumerate() {
|
||||||
match nr {
|
match nr {
|
||||||
0 => skipf[idx] = *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() {
|
for (idx, nr) in field.iter().enumerate().rev() {
|
||||||
match nr {
|
match nr {
|
||||||
0 => skipb[idx] = *nr,
|
0 => skipb[idx + 1] = *nr,
|
||||||
_ => skipb[idx] = find_fixed_streak_backward(idx, &field),
|
_ => skipb[idx + 1] = find_fixed_streak_backward(idx, &field),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -257,7 +257,7 @@ impl SField {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn prev(&mut self) -> bool {
|
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 {
|
if new_pos >= NUM_FIELDS {
|
||||||
return false;
|
return false;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user