From 8b53cbaf5e7f1a0a7eef905c449981d8895f9711 Mon Sep 17 00:00:00 2001 From: Kenta Murata 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 --- ext/bigdecimal/bigdecimal.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'ext/bigdecimal') diff --git a/ext/bigdecimal/bigdecimal.c b/ext/bigdecimal/bigdecimal.c index 189b983870..0c79cc1f78 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 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 v1.2.3