diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2016-02-28 10:37:37 -0800 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2016-02-28 10:37:37 -0800 |
commit | fa6d93b2ee8e350bcfc8006ca5c82cc612561aad (patch) | |
tree | fa81dc98deda2dc97a60306648040cde016c53e7 | |
parent | 69e418d7dd247ed45d4ea324d89953514bcae6ed (diff) | |
download | mu-fa6d93b2ee8e350bcfc8006ca5c82cc612561aad.tar.gz |
2722 - fix a crash; thanks Ella Couch!
-rw-r--r-- | 041jump_target.cc | 26 |
1 files changed, 24 insertions, 2 deletions
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 [ |