[前][次][番号順一覧][スレッド一覧]

ruby-changes:64813

From: Kenta <ko1@a...>
Date: Sun, 10 Jan 2021 08:45:43 +0900 (JST)
Subject: [ruby-changes:64813] 8b53cbaf5e (master): [ruby/bigdecimal] Avoid casting negative value to size_t

https://git.ruby-lang.org/ruby.git/commit/?id=8b53cbaf5e

From 8b53cbaf5e7f1a0a7eef905c449981d8895f9711 Mon Sep 17 00:00:00 2001
From: Kenta Murata <mrkn@m...>
Date: Sun, 10 Jan 2021 08:31:20 +0900
Subject: [ruby/bigdecimal] Avoid casting negative value to size_t

https://github.com/ruby/bigdecimal/f047b2786f

diff --git a/ext/bigdecimal/bigdecimal.c b/ext/bigdecimal/bigdecimal.c
index 189b983..0c79cc1 100644
--- a/ext/bigdecimal/bigdecimal.c
+++ b/ext/bigdecimal/bigdecimal.c
@@ -205,17 +205,18 @@ static VALUE rb_rational_convert_to_BigDecimal(VALUE val, size_t digs, int raise https://github.com/ruby/ruby/blob/trunk/ext/bigdecimal/bigdecimal.c#L205
 static Real*
 GetVpValueWithPrec(VALUE v, long prec, int must)
 {
+    const size_t digs = prec < 0 ? SIZE_MAX : (long)prec;
     Real *pv;
 
     switch(TYPE(v)) {
       case T_FLOAT: {
-        VALUE obj = rb_float_convert_to_BigDecimal(v, prec, must);
+        VALUE obj = rb_float_convert_to_BigDecimal(v, digs, must);
         TypedData_Get_Struct(obj, Real, &BigDecimal_data_type, pv);
         return pv;
       }
 
       case T_RATIONAL: {
-        VALUE obj = rb_rational_convert_to_BigDecimal(v, prec, must);
+        VALUE obj = rb_rational_convert_to_BigDecimal(v, digs, must);
         TypedData_Get_Struct(obj, Real, &BigDecimal_data_type, pv);
         return pv;
       }
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]