summaryrefslogtreecommitdiff
path: root/ext/bigdecimal
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-08-30 07:17:56 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-08-30 07:17:56 +0000
commitd7ca01a73ad5287f9d063bbdf5b35f472affda9d (patch)
treec79b2018ac56d826f7c0a716df096e5ceb9ef19d /ext/bigdecimal
parentaa7dc0f305c11c2ef9e67f6d48acbd1264022024 (diff)
bigdecimal.c: check underflow
* ext/bigdecimal/bigdecimal.c (BigDecimal_to_f): check underflow since strtod() sets errno to ERANGE at underflow too. [ruby-core:47342] [Bug #6944] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36854 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/bigdecimal')
-rw-r--r--ext/bigdecimal/bigdecimal.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/ext/bigdecimal/bigdecimal.c b/ext/bigdecimal/bigdecimal.c
index 866ce34..e8ba40a 100644
--- a/ext/bigdecimal/bigdecimal.c
+++ b/ext/bigdecimal/bigdecimal.c
@@ -696,8 +696,10 @@ BigDecimal_to_f(VALUE self)
VpToString(p, buf, 0, 0);
errno = 0;
d = strtod(buf, 0);
- if (errno == ERANGE)
- goto overflow;
+ if (errno == ERANGE) {
+ if (d == 0.0) goto underflow;
+ if (fabs(d) >= HUGE_VAL) goto overflow;
+ }
return rb_float_new(d);
overflow: