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
This commit is contained in:
Nobuyoshi Nakada 2022-10-16 00:20:58 +09:00
Родитель 7fcad1fa03
Коммит 1e3fa634f7
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 7CD2805BFA3770C6
1 изменённых файлов: 3 добавлений и 2 удалений

Просмотреть файл

@ -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));