Skip to content

Commit

Permalink
NODE_NEGATE cdr may not be code-node; fix #3348 ref #3324
Browse files Browse the repository at this point in the history
Reported by Denis Kasak https://hackerone.com/dkasak
  • Loading branch information
matz committed Dec 17, 2016
1 parent b0886d5 commit c2bbfa5
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions mrbgems/mruby-compiler/core/codegen.c
Original file line number Diff line number Diff line change
Expand Up @@ -2231,13 +2231,9 @@ codegen(codegen_scope *s, node *tree, int val)
{
nt = (intptr_t)tree->car;
tree = tree->cdr;
if (!val) {
codegen(s, tree, NOVAL);
break;
}
switch (nt) {
case NODE_FLOAT:
{
if (val) {
char *p = (char*)tree;
mrb_float f = mrb_float_read(p, NULL);
int off = new_lit(s, mrb_float_value(s->mrb, -f));
Expand All @@ -2248,7 +2244,7 @@ codegen(codegen_scope *s, node *tree, int val)
break;

case NODE_INT:
{
if (val) {
char *p = (char*)tree->car;
int base = (intptr_t)tree->cdr->car;
mrb_int i;
Expand Down Expand Up @@ -2277,7 +2273,7 @@ codegen(codegen_scope *s, node *tree, int val)
break;

default:
{
if (val) {
int sym = new_msym(s, mrb_intern_lit(s->mrb, "-"));

genop(s, MKOP_ABx(OP_LOADI, cursp(), 0));
Expand All @@ -2286,6 +2282,9 @@ codegen(codegen_scope *s, node *tree, int val)
pop(); pop();
genop(s, MKOP_ABC(OP_SUB, cursp(), sym, 2));
}
else {
codegen(s, tree, NOVAL);
}
break;
}
}
Expand Down

0 comments on commit c2bbfa5

Please sign in to comment.