diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2020-11-17 14:44:07 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2020-11-17 16:20:54 +0900 |
| commit | 68cebb63314f10171fd21c5adde31415155bc748 (patch) | |
| tree | c2d6ca0c649a8dd39046b7c859f6fd7d24ac0764 | |
| parent | a8cd364ece004097430d8d8567e06f2283106444 (diff) | |
| download | mruby-68cebb63314f10171fd21c5adde31415155bc748.tar.gz mruby-68cebb63314f10171fd21c5adde31415155bc748.zip | |
Overflown integers should not be fall back to float values.
| -rw-r--r-- | mrbgems/mruby-compiler/core/codegen.c | 47 |
1 files changed, 3 insertions, 44 deletions
diff --git a/mrbgems/mruby-compiler/core/codegen.c b/mrbgems/mruby-compiler/core/codegen.c index 34ccb6f86..b575a1ffc 100644 --- a/mrbgems/mruby-compiler/core/codegen.c +++ b/mrbgems/mruby-compiler/core/codegen.c @@ -1361,34 +1361,6 @@ raise_error(codegen_scope *s, const char *msg) genop_1(s, OP_ERR, idx); } -#ifndef MRB_NO_FLOAT -static double -readint_float(codegen_scope *s, const char *p, int base) -{ - const char *e = p + strlen(p); - double f = 0; - int n; - - if (*p == '+') p++; - while (p < e) { - char c = *p; - c = tolower((unsigned char)c); - for (n=0; n<base; n++) { - if (mrb_digitmap[n] == c) { - f *= base; - f += n; - break; - } - } - if (n == base) { - codegen_error(s, "malformed readint input"); - } - p++; - } - return f; -} -#endif - static mrb_int readint_mrb_int(codegen_scope *s, const char *p, int base, mrb_bool neg, mrb_bool *overflow) { @@ -2473,16 +2445,10 @@ codegen(codegen_scope *s, node *tree, int val) mrb_bool overflow; i = readint_mrb_int(s, p, base, FALSE, &overflow); -#ifndef MRB_NO_FLOAT if (overflow) { - double f = readint_float(s, p, base); - int off = new_lit(s, mrb_float_value(s->mrb, f)); - - genop_bs(s, OP_LOADL, cursp(), off); + codegen_error(s, "integer overflow"); } - else -#endif - { + else { if (i < 0) { if (i == -1) genop_1(s, OP_LOADI__1, cursp()); else if (i >= -0xff) genop_2(s, OP_LOADINEG, cursp(), (uint16_t)-i); @@ -2544,15 +2510,10 @@ codegen(codegen_scope *s, node *tree, int val) mrb_bool overflow; i = readint_mrb_int(s, p, base, TRUE, &overflow); -#ifndef MRB_NO_FLOAT if (overflow) { - double f = readint_float(s, p, base); - int off = new_lit(s, mrb_float_value(s->mrb, -f)); - - genop_bs(s, OP_LOADL, cursp(), off); + codegen_error(s, "integer overflow"); } else { -#endif if (i == -1) genop_1(s, OP_LOADI__1, cursp()); else if (i >= -0xff) { genop_2(s, OP_LOADINEG, cursp(), (uint16_t)-i); @@ -2567,9 +2528,7 @@ codegen(codegen_scope *s, node *tree, int val) int off = new_lit(s, mrb_int_value(s->mrb, i)); genop_bs(s, OP_LOADL, cursp(), off); } -#ifndef MRB_NO_FLOAT } -#endif push(); } break; |
