Skip to content
Snippets Groups Projects
Commit 564c95bd authored by Edvin Åkerfeldt's avatar Edvin Åkerfeldt
Browse files

cargo_klee_examples/array.rs, D

parent bddb67d2
No related branches found
No related tags found
No related merge requests found
...@@ -8,10 +8,10 @@ ...@@ -8,10 +8,10 @@
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;
for i in 0..arr.len() { for i in 0..arr.len() {
acc += arr[i as usize]; acc += arr[i as usize] as u16;
} }
acc acc
} }
...@@ -84,11 +84,18 @@ Running the test case in gdb will show yhou this in the asm code (shown code is ...@@ -84,11 +84,18 @@ Running the test case in gdb will show yhou this in the asm code (shown code is
// Explain what caused the error. // Explain what caused the error.
// //
// [your answer here] // [your answer here]
/*
The value of acc overflowed.
This was caused by klee inputing max values of u8 in the array slots which when added together greatly exedes the max of u8.
*/
// //
// 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] // [your answer here]
/*
I changed the type of the return variable to an u16, which will fit the added values.
*/
// //
// [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