diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-08-30 07:17:56 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-08-30 07:17:56 +0000 |
commit | d7ca01a73ad5287f9d063bbdf5b35f472affda9d (patch) | |
tree | c79b2018ac56d826f7c0a716df096e5ceb9ef19d /ext/bigdecimal/bigdecimal.c | |
parent | aa7dc0f305c11c2ef9e67f6d48acbd1264022024 (diff) | |
download | ruby-d7ca01a73ad5287f9d063bbdf5b35f472affda9d.tar.gz |
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/bigdecimal.c')
-rw-r--r-- | ext/bigdecimal/bigdecimal.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/ext/bigdecimal/bigdecimal.c b/ext/bigdecimal/bigdecimal.c index 866ce345fc..e8ba40a531 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: |