From 44a35f0d962a4b068a2381e82b94211bbdc7acf6 Mon Sep 17 00:00:00 2001
From: rubenasplund <ruben.asplund@hotmail.com>
Date: Thu, 17 Dec 2020 10:44:12 +0100
Subject: [PATCH] Exercise B and C

---
 cargo_klee_examples/examples/cyccnt.rs | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)

diff --git a/cargo_klee_examples/examples/cyccnt.rs b/cargo_klee_examples/examples/cyccnt.rs
index 470db78..f6e0135 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.
 //
-- 
GitLab