about summary refs log tree commit diff homepage
diff options
context:
space:
mode:
authorLukáš Zaoral <lzaoral@redhat.com>2022-01-22 21:27:43 +0100
committerCristian Cadar <c.cadar@imperial.ac.uk>2022-03-09 20:45:11 +0100
commit69190130d38bfc9b5d67add843f2c542dc843470 (patch)
tree45200c5197b071230b1b6db94222978ebb5ca4c7
parent7c80e9b86c89f5a87dcd5347b94fbb32b4137e2f (diff)
downloadklee-69190130d38bfc9b5d67add843f2c542dc843470.tar.gz
Core/ExecutionState: Fix uninitialized reads in unit tests
... by initialising all members of fundamental types of the ExecutionState
class.

Fixes the following error in SearcherTest.{Two,}RandomPath unit tests:
lib/Core/ExecutionState.cpp:114:22: runtime error: load of value 254, which is not a valid value for type 'bool'
-rw-r--r--lib/Core/ExecutionState.cpp11
-rw-r--r--lib/Core/ExecutionState.h18
2 files changed, 11 insertions, 18 deletions
diff --git a/lib/Core/ExecutionState.cpp b/lib/Core/ExecutionState.cpp
index 2f585f96..54fe752e 100644
--- a/lib/Core/ExecutionState.cpp
+++ b/lib/Core/ExecutionState.cpp
@@ -70,15 +70,8 @@ StackFrame::~StackFrame() {
 
 /***/
 
-ExecutionState::ExecutionState(KFunction *kf) :
-    pc(kf->instructions),
-    prevPC(pc),
-    depth(0),
-    ptreeNode(nullptr),
-    steppedInstructions(0),
-    instsSinceCovNew(0),
-    coveredNew(false),
-    forkDisabled(false) {
+ExecutionState::ExecutionState(KFunction *kf)
+    : pc(kf->instructions), prevPC(pc) {
   pushFrame(nullptr, kf);
   setID();
 }
diff --git a/lib/Core/ExecutionState.h b/lib/Core/ExecutionState.h
index 8f5e57e8..49e232dc 100644
--- a/lib/Core/ExecutionState.h
+++ b/lib/Core/ExecutionState.h
@@ -175,7 +175,7 @@ public:
   // Overall state of the state - Data specific
 
   /// @brief Exploration depth, i.e., number of times KLEE branched for this state
-  std::uint32_t depth;
+  std::uint32_t depth = 0;
 
   /// @brief Address space used by this state (e.g. Global and Heap)
   AddressSpace addressSpace;
@@ -219,11 +219,11 @@ public:
   std::vector<ref<MergeHandler>> openMergeStack;
 
   /// @brief The numbers of times this state has run through Executor::stepInstruction
-  std::uint64_t steppedInstructions;
+  std::uint64_t steppedInstructions = 0;
 
   /// @brief Counts how many instructions were executed since the last new
   /// instruction was covered.
-  std::uint32_t instsSinceCovNew;
+  std::uint32_t instsSinceCovNew = 0;
 
   /// @brief Keep track of unwinding state while unwinding, otherwise empty
   std::unique_ptr<UnwindingInformation> unwindingInformation;
@@ -232,19 +232,19 @@ public:
   static std::uint32_t nextID;
 
   /// @brief the state id
-  std::uint32_t id {0};
+  std::uint32_t id = 0;
 
   /// @brief Whether a new instruction was covered in this state
-  bool coveredNew;
+  bool coveredNew = false;
 
   /// @brief Disables forking for this state. Set by user code
-  bool forkDisabled;
+  bool forkDisabled = false;
 
 public:
-  #ifdef KLEE_UNITTEST
+#ifdef KLEE_UNITTEST
   // provide this function only in the context of unittests
-  ExecutionState(){}
-  #endif
+  ExecutionState() = default;
+#endif
   // only to create the initial state
   explicit ExecutionState(KFunction *kf);
   // no copy assignment, use copy constructor