about summary refs log tree commit diff stats
path: root/030container.cc
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2015-07-31 17:06:38 -0700
committerKartik K. Agaram <vc@akkartik.com>2015-07-31 17:08:30 -0700
commit18e626dfe83c21822debc6f5a56eaea2b3102220 (patch)
treebf09bff528d2fefb72bd2349cb05cfa362d7156a /030container.cc
parent37a173b8a9c09ba96f6f8b75b89ae4e9521d5273 (diff)
downloadmu-18e626dfe83c21822debc6f5a56eaea2b3102220.tar.gz
1909 - clean up all null pointers of that ilk
Diffstat (limited to '030container.cc')
-rw-r--r--030container.cc20
1 files changed, 10 insertions, 10 deletions
diff --git a/030container.cc b/030container.cc
index 41bba748..55de2a2d 100644
--- a/030container.cc
+++ b/030container.cc
@@ -107,27 +107,24 @@ GET,
 Recipe_ordinal["get"] = GET;
 :(before "End Primitive Recipe Implementations")
 case GET: {
+  products.resize(1);
   if (SIZE(ingredients) != 2) {
     raise << current_recipe_name() << ": 'get' expects exactly 2 ingredients in '" << current_instruction().to_string() << "'\n" << end();
-    products.resize(1);
     break;
   }
   reagent base = current_instruction().ingredients.at(0);
   long long int base_address = base.value;
+  if (base_address == 0) {
+    raise << current_recipe_name() << ": tried to access location 0 in '" << current_instruction().to_string() << "'\n" << end();
+    break;
+  }
   type_ordinal base_type = base.types.at(0);
   if (Type[base_type].kind != container) {
     raise << current_recipe_name () << ": first ingredient of 'get' should be a container, but got " << base.original_string << '\n' << end();
-    products.resize(1);
     break;
   }
   if (!is_literal(current_instruction().ingredients.at(1))) {
     raise << current_recipe_name() << ": second ingredient of 'get' should have type 'offset', but got " << current_instruction().ingredients.at(1).original_string << '\n' << end();
-    products.resize(1);
-    break;
-  }
-  if (base_address == 0) {
-    raise << current_recipe_name() << ": tried to access location 0 in '" << current_instruction().to_string() << "'\n" << end();
-    products.resize(1);
     break;
   }
   assert(scalar(ingredients.at(1)));
@@ -139,7 +136,6 @@ case GET: {
   trace(Primitive_recipe_depth, "run") << "address to copy is " << src << end();
   if (offset < 0 || offset >= SIZE(Type[base_type].elements)) {
     raise << current_recipe_name() << ": invalid offset " << offset << " for " << Type[base_type].name << '\n' << end();
-    products.resize(1);
     break;
   }
   type_ordinal src_type = Type[base_type].elements.at(offset).at(0);
@@ -147,7 +143,7 @@ case GET: {
   reagent tmp;
   tmp.set_value(src);
   tmp.types.push_back(src_type);
-  products.push_back(read_memory(tmp));
+  products.at(0) = read_memory(tmp);
   break;
 }
 
@@ -199,6 +195,10 @@ case GET_ADDRESS: {
   products.resize(1);
   reagent base = current_instruction().ingredients.at(0);
   long long int base_address = base.value;
+  if (base_address == 0) {
+    raise << current_recipe_name() << ": tried to access location 0 in '" << current_instruction().to_string() << "'\n" << end();
+    break;
+  }
   type_ordinal base_type = base.types.at(0);
   if (Type[base_type].kind != container) {
     raise << current_recipe_name () << ": first ingredient of 'get-address' should be a container, but got " << base.original_string << '\n' << end();