aboutsummaryrefslogtreecommitdiffstats
path: root/variable.c
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2022-10-16 00:20:58 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2022-10-16 00:26:51 +0900
commit1e3fa634f7c90bc5eab5bc7280b673333070ca84 (patch)
tree26baf22d9d857a97d2c31b0b6eb53e35a8918fc4 /variable.c
parent7fcad1fa03c21b9a9916a12b816ec886a5b68920 (diff)
downloadruby-1e3fa634f7c90bc5eab5bc7280b673333070ca84.tar.gz
Explicitly cast to uint32_t and suppress warnings by VC
``` ../src/variable.c(1440): warning C4244: 'initializing': conversion from 'double' to 'uint32_t', possible loss of data 242 ../src/variable.c(1470): warning C4244: 'initializing': conversion from 'double' to 'uint32_t', possible loss of data 243 ``` TODO: check for `newsize` overflow
Diffstat (limited to 'variable.c')
-rw-r--r--variable.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/variable.c b/variable.c
index 4b8c87bd1f..8c802082c2 100644
--- a/variable.c
+++ b/variable.c
@@ -1434,10 +1434,11 @@ rb_ensure_generic_iv_list_size(VALUE obj, uint32_t newsize)
return ivtbl;
}
+// @note May raise when there are too many instance variables.
void
rb_init_iv_list(VALUE obj)
{
- uint32_t newsize = rb_shape_get_shape(obj)->iv_count * 2.0;
+ uint32_t newsize = (uint32_t)(rb_shape_get_shape(obj)->iv_count * 2.0);
uint32_t len = ROBJECT_NUMIV(obj);
rb_ensure_iv_list_size(obj, len, newsize < len ? len : newsize);
}
@@ -1467,7 +1468,7 @@ rb_obj_ensure_iv_index_mapping(VALUE obj, ID id)
uint32_t len = ROBJECT_NUMIV(obj);
if (len <= index) {
- uint32_t newsize = (shape->iv_count + 1) * 1.25;
+ uint32_t newsize = (uint32_t)((shape->iv_count + 1) * 1.25);
rb_ensure_iv_list_size(obj, len, newsize);
}
RUBY_ASSERT(index <= ROBJECT_NUMIV(obj));