add bounds check for bpos

This commit is contained in:
mos 2024-10-10 16:33:45 +02:00
parent 74b430a498
commit fdbc4ad83d
1 changed files with 4 additions and 0 deletions

View File

@ -213,6 +213,10 @@ impl State {
Cell::Box | Cell::Goal(true) => {
let bpos = dpos + pos;
if ((bpos.1 * self.lvl.size.0) + bpos.0) as usize >= self.lvl.map.len() {
return Err(Error::BadMove(bpos));
}
match self.lvl[bpos] {
Cell::None => {
self.toggle_box(dpos);