1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

[ruby/bigdecimal] Avoid casting negative value to size_t

https://github.com/ruby/bigdecimal/f047b2786f
This commit is contained in:
Kenta Murata 2021-01-10 08:31:20 +09:00
parent 72d504c1fd
commit 8b53cbaf5e
No known key found for this signature in database
GPG key ID: CEFE8AFB6081B062

View file

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