Skip to content
Snippets Groups Projects
Commit 148e6475 authored by nilfit's avatar nilfit
Browse files

change + to wrapping_add

This gets the tests to pass again. Without this, execution stops at an
overflow.
parent 3b4c362e
No related branches found
No related tags found
No related merge requests found
...@@ -13,7 +13,7 @@ fn check_char_0(mut ch: u8) -> Result<(), ()> { ...@@ -13,7 +13,7 @@ fn check_char_0(mut ch: u8) -> Result<(), ()> {
fn check_char_1(mut ch: u8) -> Result<(), ()> { fn check_char_1(mut ch: u8) -> Result<(), ()> {
ch ^= 107; ch ^= 107;
ch += 67; ch = ch.wrapping_add(67);
if ch == 105 { if ch == 105 {
Ok(()) Ok(())
...@@ -23,7 +23,7 @@ fn check_char_1(mut ch: u8) -> Result<(), ()> { ...@@ -23,7 +23,7 @@ fn check_char_1(mut ch: u8) -> Result<(), ()> {
} }
fn check_char_2(mut ch: u8) -> Result<(), ()> { fn check_char_2(mut ch: u8) -> Result<(), ()> {
ch += 61; ch = ch.wrapping_add(61);
ch *= 2; ch *= 2;
if ch == 252 { if ch == 252 {
...@@ -66,7 +66,7 @@ fn check_char_5(mut ch: u8) -> Result<(), ()> { ...@@ -66,7 +66,7 @@ fn check_char_5(mut ch: u8) -> Result<(), ()> {
} }
fn check_char_6(mut ch: u8) -> Result<(), ()> { fn check_char_6(mut ch: u8) -> Result<(), ()> {
ch += 71; ch = ch.wrapping_add(71);
if ch == 138 { if ch == 138 {
Ok(()) Ok(())
...@@ -86,8 +86,8 @@ fn check_char_7(mut ch: u8) -> Result<(), ()> { ...@@ -86,8 +86,8 @@ fn check_char_7(mut ch: u8) -> Result<(), ()> {
} }
fn check_char_8(mut ch: u8) -> Result<(), ()> { fn check_char_8(mut ch: u8) -> Result<(), ()> {
ch += 41; ch = ch.wrapping_add(41);
ch += 53; ch = ch.wrapping_add(53);
if ch == 176 { if ch == 176 {
Ok(()) Ok(())
...@@ -98,8 +98,8 @@ fn check_char_8(mut ch: u8) -> Result<(), ()> { ...@@ -98,8 +98,8 @@ fn check_char_8(mut ch: u8) -> Result<(), ()> {
fn check_char_9(mut ch: u8) -> Result<(), ()> { fn check_char_9(mut ch: u8) -> Result<(), ()> {
ch ^= 61; ch ^= 61;
ch += 41; ch = ch.wrapping_add(41);
ch += 11; ch = ch.wrapping_add(11);
if ch == 172 { if ch == 172 {
Ok(()) Ok(())
...@@ -110,8 +110,8 @@ fn check_char_9(mut ch: u8) -> Result<(), ()> { ...@@ -110,8 +110,8 @@ fn check_char_9(mut ch: u8) -> Result<(), ()> {
fn check_char_10(mut ch: u8) -> Result<(), ()> { fn check_char_10(mut ch: u8) -> Result<(), ()> {
ch ^= 47; ch ^= 47;
ch += 29; ch = ch.wrapping_add(29);
ch += 67; ch = ch.wrapping_add(67);
if ch == 114 { if ch == 114 {
Ok(()) Ok(())
......
...@@ -11,7 +11,7 @@ fn main() { ...@@ -11,7 +11,7 @@ fn main() {
let d0 = data[0]; // 2 let d0 = data[0]; // 2
let d1 = data[1]; // 4 let d1 = data[1]; // 4
if (d0 + d1) as usize >= v.len() { if (d0.wrapping_add(d1)) as usize >= v.len() {
return; return;
} }
......
...@@ -10,11 +10,11 @@ fn main() { ...@@ -10,11 +10,11 @@ fn main() {
// should panic on [ 7, 3, 21, 21 ] // should panic on [ 7, 3, 21, 21 ]
if data.len() >= 4 { if data.len() >= 4 {
let mut v = [0; BUFFER_LENGTH]; let mut v: [u8; BUFFER_LENGTH] = [0; BUFFER_LENGTH];
v[0] += data[3]; v[0] = v[0].wrapping_add(data[3]);
v[1] = v[0] + data[2]; v[1] = v[0].wrapping_add(data[2]);
if v[0] == 21 && v[1] == 42 { if v[0] == 21 && v[1] == 42 {
v[0] = data[0] + data[1]; v[0] = data[0].wrapping_add(data[1]);
v[3] = data[0]; v[3] = data[0];
if v[3] == 7 && v[0] == 10 { if v[3] == 7 && v[0] == 10 {
panic!() panic!()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment