diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2012-09-04 14:11:35 -0700 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2012-09-04 14:11:35 -0700 |
| commit | 3f2743c3e13e4a70649e07d84a3cda78f034d12a (patch) | |
| tree | 1023010b5e07882beea8857a7e3a6bf1b887981a /src | |
| parent | 9c3f070a8c9d45bb01bdb3d8e22cd94517c4f151 (diff) | |
| parent | 65f855b0442551e89941c1b383e6fd27c7b7e65e (diff) | |
| download | mruby-3f2743c3e13e4a70649e07d84a3cda78f034d12a.tar.gz mruby-3f2743c3e13e4a70649e07d84a3cda78f034d12a.zip | |
Merge pull request #447 from iij/pr-tailcall-oob
fix out-of-bound access on compiling empty blocks.
Diffstat (limited to 'src')
| -rw-r--r-- | src/codegen.c | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/src/codegen.c b/src/codegen.c index 49d53b1ea..799ec1500 100644 --- a/src/codegen.c +++ b/src/codegen.c @@ -511,9 +511,10 @@ for_body(codegen_scope *s, node *tree) } codegen(s, tree->cdr->cdr->car, VAL); pop(); - c = s->iseq[s->pc-1]; - if (GET_OPCODE(c) != OP_RETURN || GETARG_B(c) != OP_R_NORMAL || s->pc == s->lastlabel) { - genop_peep(s, MKOP_AB(OP_RETURN, cursp(), OP_R_NORMAL), NOVAL); + if (s->pc > 0) { + c = s->iseq[s->pc-1]; + if (GET_OPCODE(c) != OP_RETURN || GETARG_B(c) != OP_R_NORMAL || s->pc == s->lastlabel) + genop_peep(s, MKOP_AB(OP_RETURN, cursp(), OP_R_NORMAL), NOVAL); } loop_pop(s, NOVAL); scope_finish(s, idx); @@ -593,14 +594,16 @@ lambda_body(codegen_scope *s, node *tree, int blk) } codegen(s, tree->cdr->car, VAL); pop(); - c = s->iseq[s->pc-1]; - if (GET_OPCODE(c) != OP_RETURN || GETARG_B(c) != OP_R_NORMAL || s->pc == s->lastlabel) { - if (s->nregs == 0) { - genop(s, MKOP_A(OP_LOADNIL, 0)); - genop(s, MKOP_AB(OP_RETURN, 0, OP_R_NORMAL)); - } - else { - genop_peep(s, MKOP_AB(OP_RETURN, cursp(), OP_R_NORMAL), NOVAL); + if (s->pc > 0) { + c = s->iseq[s->pc-1]; + if (GET_OPCODE(c) != OP_RETURN || GETARG_B(c) != OP_R_NORMAL || s->pc == s->lastlabel) { + if (s->nregs == 0) { + genop(s, MKOP_A(OP_LOADNIL, 0)); + genop(s, MKOP_AB(OP_RETURN, 0, OP_R_NORMAL)); + } + else { + genop_peep(s, MKOP_AB(OP_RETURN, cursp(), OP_R_NORMAL), NOVAL); + } } } if (blk) { |
