diff options
-rw-r--r-- | variable.c | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/variable.c b/variable.c index c729a08803..9c3ce2d182 100644 --- a/variable.c +++ b/variable.c @@ -1079,11 +1079,12 @@ gen_ivtbl_dup(const struct gen_ivtbl *orig) static uint32_t iv_index_tbl_newsize(struct ivar_update *ivup) { - uint32_t newsize = (ivup->index+1) + (ivup->index+1)/4; /* (index+1)*1.25 */ + uint32_t index = (uint32_t)ivup->index; /* should not overflow */ + uint32_t newsize = (index+1) + (index+1)/4; /* (index+1)*1.25 */ if (!ivup->iv_extended && ivup->u.iv_index_tbl->num_entries < (st_index_t)newsize) { - newsize = ivup->u.iv_index_tbl->num_entries; + newsize = (uint32_t)ivup->u.iv_index_tbl->num_entries; } return newsize; } @@ -1381,7 +1382,7 @@ rb_ivar_set(VALUE obj, ID id, VALUE val) } else { VALUE *newptr; - long newsize = iv_index_tbl_newsize(&ivup); + uint32_t newsize = iv_index_tbl_newsize(&ivup); if (RBASIC(obj)->flags & ROBJECT_EMBED) { newptr = ALLOC_N(VALUE, newsize); |