]> git.lizzy.rs Git - rust.git/commitdiff
Merge pull request #234 from RalfJung/reallocate
authorOliver Schneider <oli-obk@users.noreply.github.com>
Wed, 5 Jul 2017 17:54:54 +0000 (19:54 +0200)
committerGitHub <noreply@github.com>
Wed, 5 Jul 2017 17:54:54 +0000 (19:54 +0200)
Make Reallocate & Deallocate less permissive

1  2 
src/eval_context.rs
src/memory.rs
src/terminator/mod.rs

index 14639ac9e20c8ef101e1b05a0821cdb5dc3980e2,b101a3967a72344be2ec8a4b1cbef9bda21a5518..2ecc4f029e89f0b2aa8ce1772ef143159be296c9
@@@ -410,9 -409,8 +410,9 @@@ impl<'a, 'tcx> EvalContext<'a, 'tcx> 
      pub fn deallocate_local(&mut self, local: Option<Value>) -> EvalResult<'tcx> {
          if let Some(Value::ByRef(ptr)) = local {
              trace!("deallocating local");
 +            let ptr = ptr.to_ptr()?;
              self.memory.dump_alloc(ptr.alloc_id);
-             match self.memory.deallocate(ptr) {
+             match self.memory.deallocate(ptr, None) {
                  // We could alternatively check whether the alloc_id is static before calling
                  // deallocate, but this is much simpler and is probably the rare case.
                  Ok(()) | Err(EvalError::DeallocatedStaticMemory) => {},
diff --cc src/memory.rs
Simple merge
index 62446cbfa39d3c1428916dfadeedabfa3b3c3eb4,4bcf7470ba894154f9c0161e2914e53f5841a7f1..9b0596d58da03dc44637d7bbf2776c86a661e61c
@@@ -792,10 -792,10 +792,10 @@@ impl<'a, 'tcx> EvalContext<'a, 'tcx> 
                  if let Some((name, value)) = new {
                      // +1 for the null terminator
                      let value_copy = self.memory.allocate((value.len() + 1) as u64, 1)?;
 -                    self.memory.write_bytes(value_copy, &value)?;
 -                    self.memory.write_bytes(value_copy.offset(value.len() as u64, self.memory.layout)?, &[0])?;
 +                    self.memory.write_bytes(PrimVal::Ptr(value_copy), &value)?;
 +                    self.memory.write_bytes(PrimVal::Ptr(value_copy.offset(value.len() as u64, self.memory.layout)?), &[0])?;
                      if let Some(var) = self.env_vars.insert(name.to_owned(), value_copy) {
-                         self.memory.deallocate(var)?;
+                         self.memory.deallocate(var, None)?;
                      }
                      self.write_primval(dest, PrimVal::Bytes(0), dest_ty)?;
                  } else {