[ruby/bigdecimal] Avoid casting negative value to size_t
https://github.com/ruby/bigdecimal/f047b2786f
This commit is contained in:
parent
72d504c1fd
commit
8b53cbaf5e
@ -205,17 +205,18 @@ static VALUE rb_rational_convert_to_BigDecimal(VALUE val, size_t digs, int raise
|
|||||||
static Real*
|
static Real*
|
||||||
GetVpValueWithPrec(VALUE v, long prec, int must)
|
GetVpValueWithPrec(VALUE v, long prec, int must)
|
||||||
{
|
{
|
||||||
|
const size_t digs = prec < 0 ? SIZE_MAX : (long)prec;
|
||||||
Real *pv;
|
Real *pv;
|
||||||
|
|
||||||
switch(TYPE(v)) {
|
switch(TYPE(v)) {
|
||||||
case T_FLOAT: {
|
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);
|
TypedData_Get_Struct(obj, Real, &BigDecimal_data_type, pv);
|
||||||
return pv;
|
return pv;
|
||||||
}
|
}
|
||||||
|
|
||||||
case T_RATIONAL: {
|
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);
|
TypedData_Get_Struct(obj, Real, &BigDecimal_data_type, pv);
|
||||||
return pv;
|
return pv;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user