From fa6d93b2ee8e350bcfc8006ca5c82cc612561aad Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Sun, 28 Feb 2016 10:37:37 -0800 Subject: 2722 - fix a crash; thanks Ella Couch! --- 041jump_target.cc | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to '041jump_target.cc') diff --git a/041jump_target.cc b/041jump_target.cc index 7fd49c7c..36d43df9 100644 --- a/041jump_target.cc +++ b/041jump_target.cc @@ -40,18 +40,26 @@ void transform_labels(const recipe_ordinal r) { for (long long int i = 0; i < SIZE(get(Recipe, r).steps); ++i) { instruction& inst = get(Recipe, r).steps.at(i); if (inst.name == "jump") { + if (inst.ingredients.empty()) { + raise << maybe(get(Recipe, r).name) << "'jump' expects an ingredient but got none\n" << end(); + return; + } replace_offset(inst.ingredients.at(0), offset, i, r); } if (inst.name == "jump-if" || inst.name == "jump-unless") { + if (SIZE(inst.ingredients) < 2) { + raise << maybe(get(Recipe, r).name) << "'" << inst.name << "' expects 2 ingredients but got " << SIZE(inst.ingredients) << '\n' << end(); + return; + } replace_offset(inst.ingredients.at(1), offset, i, r); } if ((inst.name == "loop" || inst.name == "break") - && SIZE(inst.ingredients) == 1) { + && SIZE(inst.ingredients) >= 1) { replace_offset(inst.ingredients.at(0), offset, i, r); } if ((inst.name == "loop-if" || inst.name == "loop-unless" || inst.name == "break-if" || inst.name == "break-unless") - && SIZE(inst.ingredients) == 2) { + && SIZE(inst.ingredients) >= 2) { replace_offset(inst.ingredients.at(1), offset, i, r); } } @@ -133,6 +141,20 @@ recipe main [ +mem: storing 0 in location 5 -mem: storing 0 in location 4 +:(scenario jump_fails_without_target) +% Hide_errors = true; +recipe main [ + jump +] ++error: main: 'jump' expects an ingredient but got none + +:(scenario jump_fails_without_target_2) +% Hide_errors = true; +recipe main [ + jump-if 1/true +] ++error: main: 'jump-if' expects 2 ingredients but got 1 + :(scenario recipe_fails_on_duplicate_jump_target) % Hide_errors = true; recipe main [ -- cgit 1.4.1-2-gfad0