diff --git a/cargo_klee_examples/examples/cyccnt.rs b/cargo_klee_examples/examples/cyccnt.rs index 470db780679513c7450cf354f133df7a9be485bd..f6e0135083906e523ef9ba358d384ef6abb4511f 100644 --- a/cargo_klee_examples/examples/cyccnt.rs +++ b/cargo_klee_examples/examples/cyccnt.rs @@ -19,7 +19,7 @@ fn main() { let end = core.DWT.cyccnt.read(); - let _time = end - start; + // let _time = end.wrapping_sub(start); } // A) Running KLEE on embedded code: @@ -166,7 +166,9 @@ fn main() { // // What do you get, and why? // -// [There are no value of start or end because both are optimized out.] +// [There are no value of start or end because both are optimized out. +// The variables are used for substraction, the difference value is is thrown away. +// Then start and end is useless, therefore they are optimized out.] // // As you should have seen, this was not particularly informative, right? // @@ -197,15 +199,19 @@ fn main() { // // Value of `start`. // -// [your answer here] +// [start = 0] // // Value of `end` // -// [your answer here] +// [end = 0] // // Why does these values cause an error debug/dev build but not in a release build? // -// [your answer here] +// [This line is causing the problem: let _time = end - start; +// When taking substraction of values two values there is a high risk that it will overflow, +// therefore the error occurs in debug/dev build. +// In release build the substractions occurs and no overflow is found then errors will not occurs. +// It seems like the release build is not detecting potential problems, only problems that occurs.] // // C) Fix the problem! // @@ -217,7 +223,8 @@ fn main() { // There are numerous ways to solve the problem. // Argue for your solution in your own words. // -// [your answer here] +// [The substraction can overflow, to remove the error and make sure the substraction is almost always correct, +// we need to use wrapper_sub.] // // D) Learning outcomes and major takeaways. //