From 89b87bc7c493670ecb598784e1073a09f691d43e Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Wed, 29 Jul 2015 18:40:36 -0700 Subject: 1886 - gracefully handle malformed ingredients For example: x:number <- index y:address:array:number, 3 (forgetting to do a lookup) Thanks Caleb Couch. --- 030container.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to '030container.cc') diff --git a/030container.cc b/030container.cc index 46314d00..15a6eb6f 100644 --- a/030container.cc +++ b/030container.cc @@ -109,6 +109,7 @@ Recipe_ordinal["get"] = GET; case GET: { 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); @@ -116,10 +117,12 @@ case GET: { 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; } assert(scalar(ingredients.at(1))); @@ -188,6 +191,7 @@ GET_ADDRESS, Recipe_ordinal["get-address"] = GET_ADDRESS; :(before "End Primitive Recipe Implementations") case GET_ADDRESS: { + products.resize(1); reagent base = current_instruction().ingredients.at(0); long long int base_address = base.value; type_ordinal base_type = base.types.at(0); @@ -203,7 +207,6 @@ case GET_ADDRESS: { long long int offset = ingredients.at(1).at(0); if (offset < 0 || offset >= SIZE(Type[base_type].elements)) { raise << "invalid offset " << offset << " for " << Type[base_type].name << '\n' << end(); - products.resize(1); break; } long long int result = base_address; @@ -211,7 +214,6 @@ case GET_ADDRESS: { result += size_of(Type[base_type].elements.at(i)); } trace(Primitive_recipe_depth, "run") << "address to copy is " << result << end(); - products.resize(1); products.at(0).push_back(result); break; } -- cgit 1.4.1-2-gfad0