ruby-changes:74015
From: Nobuyoshi <ko1@a...>
Date: Sun, 16 Oct 2022 00:34:58 +0900 (JST)
Subject: [ruby-changes:74015] 1e3fa634f7 (master): Explicitly cast to uint32_t and suppress warnings by VC
https://git.ruby-lang.org/ruby.git/commit/?id=1e3fa634f7 From 1e3fa634f7c90bc5eab5bc7280b673333070ca84 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Sun, 16 Oct 2022 00:20:58 +0900 Subject: 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 --- variable.c | 5 +++-- 1 file 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) https://github.com/ruby/ruby/blob/trunk/variable.c#L1434 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) https://github.com/ruby/ruby/blob/trunk/variable.c#L1468 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)); -- cgit v1.2.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/