From 18e626dfe83c21822debc6f5a56eaea2b3102220 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Fri, 31 Jul 2015 17:06:38 -0700 Subject: 1909 - clean up all null pointers of that ilk --- 030container.cc | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to '030container.cc') 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(); -- cgit 1.4.1-2-gfad0