about summary refs log tree commit diff homepage
path: root/lib
diff options
context:
space:
mode:
authorDan Liew <daniel.liew@imperial.ac.uk>2013-08-13 15:34:39 +0100
committerDan Liew <daniel.liew@imperial.ac.uk>2013-08-14 18:44:16 +0100
commit51f7cb3a3b494bd38ad9b3aec72a32f7973b8a06 (patch)
tree96916aae5a1ee3bfd1729afef009a59d67d3cc04 /lib
parente211c407bcf1631c448800cb49044b2f48bee638 (diff)
downloadklee-51f7cb3a3b494bd38ad9b3aec72a32f7973b8a06.tar.gz
Slight refactor of code initialising memory for argments/environment c-strings
so that it is easier to read.
Diffstat (limited to 'lib')
-rw-r--r--lib/Core/Executor.cpp12
1 files changed, 4 insertions, 8 deletions
diff --git a/lib/Core/Executor.cpp b/lib/Core/Executor.cpp
index b57b1956..184b0983 100644
--- a/lib/Core/Executor.cpp
+++ b/lib/Core/Executor.cpp
@@ -3219,24 +3219,20 @@ void Executor::runFunctionAsMain(Function *f,
     ObjectState *argvOS = bindObjectInState(*state, argvMO, false);
 
     for (int i=0; i<argc+1+envc+1+1; i++) {
-      MemoryObject *arg;
-      
       if (i==argc || i>=argc+1+envc) {
-        arg = 0;
+        // Write NULL pointer
+        argvOS->write(i * NumPtrBytes, Expr::createPointer(0));
       } else {
         char *s = i<argc ? argv[i] : envp[i-(argc+1)];
         int j, len = strlen(s);
         
-        arg = memory->allocate(len+1, false, true, state->pc->inst);
+        MemoryObject *arg = memory->allocate(len+1, false, true, state->pc->inst);
         ObjectState *os = bindObjectInState(*state, arg, false);
         for (j=0; j<len+1; j++)
           os->write8(j, s[j]);
-      }
 
-      if (arg) {
+        // Write pointer to newly allocated and initialised argv/envp c-string
         argvOS->write(i * NumPtrBytes, arg->getBaseExpr());
-      } else {
-        argvOS->write(i * NumPtrBytes, Expr::createPointer(0));
       }
     }
   }