Skip to content
Snippets Groups Projects
Commit 8bb1d3e2 authored by Ruben Asplund's avatar Ruben Asplund
Browse files

D

parent 0d5f7f24
No related branches found
No related tags found
No related merge requests found
...@@ -8,11 +8,11 @@ ...@@ -8,11 +8,11 @@
use klee_sys::klee_make_symbolic; use klee_sys::klee_make_symbolic;
use panic_klee as _; use panic_klee as _;
fn sum_first_elements(arr: &[u8], index: usize) -> u8 { fn sum_first_elements(arr: &[u8], index: usize) -> u16 {
let mut acc = 0; let mut acc: u16 = 0;
let index = core::cmp::min(arr.len(), index); let index = core::cmp::min(arr.len(), index);
for i in 0..index { for i in 0..index {
acc += arr[i as usize]; acc += arr[i as usize] as u16;
} }
acc acc
} }
...@@ -65,12 +65,12 @@ fn main() { ...@@ -65,12 +65,12 @@ fn main() {
// //
// Explain what caused the error. // Explain what caused the error.
// //
// [your answer here] // [It seems to be a overflow problem in the varaible acc.]
// //
// E) Make a sensible fix to the code. // E) Make a sensible fix to the code.
// Motivate your choice. // Motivate your choice.
// //
// [your answer here] // [I changed the acc variable to a u16. It will allow bigger values without overflowing.]
// //
// [Git commit "D"] // [Git commit "D"]
// //
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment