summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2018-04-17 23:08:36 +0900
committerGitHub <[email protected]>2018-04-17 23:08:36 +0900
commitf7cf5812b1288d6ca21daff31b4a2b91ea2a06ed (patch)
tree686329358b0084b362f971707c79328dd7e3ffd8
parent4880f6dc8982dc794a7ed149ed6fef86821e8257 (diff)
parent87ef6aeb02b75f71138a0b3a74db00e5a366efed (diff)
downloadmruby-f7cf5812b1288d6ca21daff31b4a2b91ea2a06ed.tar.gz
mruby-f7cf5812b1288d6ca21daff31b4a2b91ea2a06ed.zip
Merge pull request #4003 from take-cheeze/int32_overflow
Fallback to float when compiled binary with 64bit compiler.
-rw-r--r--src/load.c7
-rw-r--r--src/string.c9
2 files changed, 11 insertions, 5 deletions
diff --git a/src/load.c b/src/load.c
index 58427424d..3a6ce7cca 100644
--- a/src/load.c
+++ b/src/load.c
@@ -126,9 +126,10 @@ read_irep_record_1(mrb_state *mrb, const uint8_t *bin, size_t *len, uint8_t flag
}
src += pool_data_len;
switch (tt) { /* pool data */
- case IREP_TT_FIXNUM:
- irep->pool[i] = mrb_str_to_inum(mrb, s, 10, FALSE);
- break;
+ case IREP_TT_FIXNUM: {
+ mrb_value num = mrb_str_to_inum(mrb, s, 10, FALSE);
+ irep->pool[i] = mrb_float_p(num)? mrb_float_pool(mrb, mrb_float(num)) : num;
+ } break;
#ifndef MRB_WITHOUT_FLOAT
case IREP_TT_FLOAT:
diff --git a/src/string.c b/src/string.c
index 469335bb9..8ebd11b6c 100644
--- a/src/string.c
+++ b/src/string.c
@@ -2167,8 +2167,13 @@ mrb_str_len_to_inum(mrb_state *mrb, const char *str, mrb_int len, mrb_int base,
n *= base;
n += c;
if (n > (uint64_t)MRB_INT_MAX + (sign ? 0 : 1)) {
- mrb_raisef(mrb, E_ARGUMENT_ERROR, "string (%S) too big for integer",
- mrb_str_new(mrb, str, pend-str));
+ if (base == 10) {
+ return mrb_float_value(mrb, mrb_str_to_dbl(mrb, mrb_str_new(mrb, str, len), badcheck));
+ }
+ else {
+ mrb_raisef(mrb, E_ARGUMENT_ERROR, "string (%S) too big for integer",
+ mrb_str_new(mrb, str, pend-str));
+ }
}
}
val = (mrb_int)n;