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:
parent
72d504c1fd
commit
8b53cbaf5e
1 changed files with 3 additions and 2 deletions
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue