From 9f860c9b64e62c5cfdf524aa25e8d00cd2fc434c Mon Sep 17 00:00:00 2001 From: Blinningjr <nicke.l@telia.com> Date: Tue, 15 Dec 2020 00:43:26 +0100 Subject: [PATCH] B --- cargo_klee_examples/examples/array.rs | 23 +++++++++++++++++++++-- cargo_klee_examples/examples/get_sign.rs | 3 ++- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/cargo_klee_examples/examples/array.rs b/cargo_klee_examples/examples/array.rs index 9ec5e10..f1fa1b7 100644 --- a/cargo_klee_examples/examples/array.rs +++ b/cargo_klee_examples/examples/array.rs @@ -11,7 +11,11 @@ use panic_klee as _; fn sum_first_elements(arr: &[u8], index: usize) -> u8 { let mut acc = 0; for i in 0..index { - acc += arr[i as usize]; + if index < arr.len() { + acc += arr[i as usize]; + } else { + break; + } } acc } @@ -37,7 +41,22 @@ fn main() { // Try to explain in your own words the difference and why? // (Hint, even if we don't use the result `b`, Rust do not optimize out the call, why?) // -// [your answer here] +// [your answer here]] +// The diffrence is that debug test all 10 possible paths and release only checks 2. This is becaus +// 9 of the paths are basicly the same. These are the path were index is 0..8, the last path is +// diffrent because then the index is out side of the array(index = 255), thus there will be an error. +// +// +// Debug: +// KLEE: done: total instructions = 4686 +// KLEE: done: completed paths = 10 +// KLEE: done: generated tests = 10 +// +// Release: +// KLEE: done: total instructions = 32 +// KLEE: done: completed paths = 2 +// KLEE: done: generated tests = 2 +// // // B) Fix the code so that you don't get an error. // (It should still compute the sum of the n first elements diff --git a/cargo_klee_examples/examples/get_sign.rs b/cargo_klee_examples/examples/get_sign.rs index 56fe57c..c955577 100644 --- a/cargo_klee_examples/examples/get_sign.rs +++ b/cargo_klee_examples/examples/get_sign.rs @@ -85,7 +85,8 @@ fn main() { // // [your answer here] // There are a lot of flags in the command which makes it a bit long to write. Maybe add a new -// command for emitting llvm-ir files or maybe combine some of the flags into one. +// command for emitting llvm-ir files or maybe add a combinedflag that combines some of the flags +// into one. // // C) Inner workings. // -- GitLab