summaryrefslogtreecommitdiff
path: root/ext/bigdecimal
diff options
context:
space:
mode:
authorKenta Murata <mrkn@mrkn.jp>2021-01-10 08:31:20 +0900
committerKenta Murata <mrkn@mrkn.jp>2021-01-10 08:36:29 +0900
commit8b53cbaf5e7f1a0a7eef905c449981d8895f9711 (patch)
treec7dd402b67a684b0c0ddbafff04904bec0ed200b /ext/bigdecimal
parent72d504c1fde34894d797ac7fb881609d81711e06 (diff)
[ruby/bigdecimal] Avoid casting negative value to size_t
https://github.com/ruby/bigdecimal/f047b2786f
Diffstat (limited to 'ext/bigdecimal')
-rw-r--r--ext/bigdecimal/bigdecimal.c5
1 files changed, 3 insertions, 2 deletions
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
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;
}