Skip to content

Commit 71bbfec

Browse files
author
robo9k
committed
Use WrappingOps for intended overflow behaviour
1 parent e4f8d83 commit 71bbfec

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/vm.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ impl Vm {
201201
self.reg[vx as usize] = byte;
202202
},
203203
AddK(vx, byte) => {
204-
self.reg[vx as usize] += byte;
204+
self.reg[vx as usize] = self.reg[vx as usize].wrapping_add(byte);
205205
},
206206
Set(vx, vy) => self.reg[vx as usize] = self.reg[vy as usize],
207207
Or(vx, vy) => self.reg[vx as usize] |= self.reg[vy as usize],
@@ -224,7 +224,7 @@ impl Vm {
224224
// VF is Not Borrow i.e. x > y
225225
self.reg[Register::VF as usize] = (x > y) as u8;
226226

227-
self.reg[vx as usize] = x - y;
227+
self.reg[vx as usize] = x.wrapping_sub(y);
228228
},
229229
ShiftRight(vx, vy) => {
230230
let y = self.reg[vy as usize];
@@ -241,7 +241,7 @@ impl Vm {
241241
// VF is Not Borrow i.e. y > x
242242
self.reg[Register::VF as usize] = (y > x) as u8;
243243

244-
self.reg[vx as usize] = y - x;
244+
self.reg[vx as usize] = y.wrapping_sub(x);
245245
},
246246
ShiftLeft(vx, vy) => {
247247
let y = self.reg[vy as usize];

0 commit comments

Comments
 (0)