Skip to content

Commit

Permalink
Avoid underflow panics in takeback()
Browse files Browse the repository at this point in the history
  • Loading branch information
kristopherjohnson committed Feb 17, 2019
1 parent 971ae15 commit 68c2a92
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/board.rs
Original file line number Diff line number Diff line change
Expand Up @@ -555,8 +555,14 @@ pub fn makemove(d: &mut Data, m: MoveBytes) -> bool {
pub fn takeback(d: &mut Data) {
d.side ^= 1;
d.xside ^= 1;
d.ply -= 1;
d.hply -= 1;
// #rust Need to avoid underflow of ply and hply, which are unsigned, or
// debug builds will panic on an "undo" command in main().
if d.ply > 0 {
d.ply -= 1
};
if d.hply > 0 {
d.hply -= 1
};
let m = d.hist_dat[d.hply].m.bytes();
d.castle = d.hist_dat[d.hply].castle;
d.ep = d.hist_dat[d.hply].ep;
Expand Down

0 comments on commit 68c2a92

Please sign in to comment.