about summary refs log tree commit diff stats
path: root/035lookup.cc
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2018-05-25 13:31:26 -0700
committerKartik Agaram <vc@akkartik.com>2018-05-25 13:31:26 -0700
commitaa94778639fda88034bbd8d979b15d8241b78a6a (patch)
tree6fe2f3ff597276107186e423490f0d7cf1a2a5d7 /035lookup.cc
parent63139d901c0d4150e9d2861e8bbb8ed139d14b06 (diff)
downloadmu-aa94778639fda88034bbd8d979b15d8241b78a6a.tar.gz
4250
Avoid modifying memory *before* the null check.
Diffstat (limited to '035lookup.cc')
-rw-r--r--035lookup.cc8
1 files changed, 5 insertions, 3 deletions
diff --git a/035lookup.cc b/035lookup.cc
index 650b8549..1823ae3d 100644
--- a/035lookup.cc
+++ b/035lookup.cc
@@ -82,9 +82,10 @@ void lookup_memory(reagent& x) {
 }
 
 void lookup_memory_core(reagent& x, bool check_for_null) {
-  trace("mem") << "location " << x.value << " is " << no_scientific(get_or_insert(Memory, x.value)) << end();
-  x.set_value(get_or_insert(Memory, x.value));
-  if (check_for_null && x.value == 0) {
+  double address = x.value;
+  double new_value = get_or_insert(Memory, address);
+  trace("mem") << "location " << address << " contains " << no_scientific(new_value) << end();
+  if (check_for_null && new_value == 0) {
     if (Current_routine) {
       raise << maybe(current_recipe_name()) << "tried to lookup 0 in '" << to_original_string(current_instruction()) << "'\n" << end();
       dump_callstack();
@@ -93,6 +94,7 @@ void lookup_memory_core(reagent& x, bool check_for_null) {
       raise << "tried to lookup 0\n" << end();
     }
   }
+  x.set_value(new_value);
   drop_from_type(x, "address");
   drop_one_lookup(x);
 }