diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2015-07-29 18:40:36 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2015-07-29 18:40:36 -0700 |
commit | 89b87bc7c493670ecb598784e1073a09f691d43e (patch) | |
tree | b645853bb524a9a57a897a729269786aad8c4ce6 /030container.cc | |
parent | 9570363aec35e187e2395b1760a4b94e71580ac9 (diff) | |
download | mu-89b87bc7c493670ecb598784e1073a09f691d43e.tar.gz |
1886 - gracefully handle malformed ingredients
For example: x:number <- index y:address:array:number, 3 (forgetting to do a lookup) Thanks Caleb Couch.
Diffstat (limited to '030container.cc')
-rw-r--r-- | 030container.cc | 6 |
1 files changed, 4 insertions, 2 deletions
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; } |