From 7fc59a0c42c9ff6d131decee7526e33494ff860d Mon Sep 17 00:00:00 2001 From: Tobias Kraze Date: Fri, 22 Nov 2013 03:51:11 +0000 Subject: [PATCH] merge revision(s) 43775: * util.c (ruby_strtod): ignore too long fraction part, which does not affect the result. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_3@43776 b2dd03c8-39d4-4d8f-98ff-823fe69b080e Conflicts: test/ruby/test_float.rb version.h merge revision(s) 43780: * util.c (ruby_strtod): BigMath requires more precision. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_3@43782 b2dd03c8-39d4-4d8f-98ff-823fe69b080e Conflicts: version.h --- test/ruby/test_float.rb | 6 ++++++ util.c | 14 ++++++++++++-- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/test/ruby/test_float.rb b/test/ruby/test_float.rb index b6e643d..b696a0a 100644 --- a/test/ruby/test_float.rb +++ b/test/ruby/test_float.rb @@ -171,4 +171,10 @@ class TestFloat < Test::Unit::TestCase assert_raise(ArgumentError) { 1.0 < nil } assert_raise(ArgumentError) { 1.0 <= nil } end + + def test_long_string + 5.times do + assert_in_delta(10.0, (("1."+"1"*300000).to_f*9), Float::EPSILON) + end + end end diff --git a/util.c b/util.c index 62f3368..54a1604 100644 --- a/util.c +++ b/util.c @@ -892,6 +892,11 @@ extern void *MALLOC(size_t); #else #define MALLOC malloc #endif +#ifdef FREE +extern void FREE(void*); +#else +#define FREE free +#endif #ifndef Omit_Private_Memory #ifndef PRIVATE_MEM @@ -1176,7 +1181,7 @@ Balloc(int k) #endif ACQUIRE_DTOA_LOCK(0); - if ((rv = freelist[k]) != 0) { + if (k <= Kmax && (rv = freelist[k]) != 0) { freelist[k] = rv->next; } else { @@ -1186,7 +1191,7 @@ Balloc(int k) #else len = (sizeof(Bigint) + (x-1)*sizeof(ULong) + sizeof(double) - 1) /sizeof(double); - if (pmem_next - private_mem + len <= PRIVATE_mem) { + if (k <= Kmax && pmem_next - private_mem + len <= PRIVATE_mem) { rv = (Bigint*)pmem_next; pmem_next += len; } @@ -1205,6 +1210,10 @@ static void Bfree(Bigint *v) { if (v) { + if (v->k > Kmax) { + FREE(v); + return; + } ACQUIRE_DTOA_LOCK(0); v->next = freelist[v->k]; freelist[v->k] = v; @@ -2200,6 +2209,7 @@ break2: for (; c >= '0' && c <= '9'; c = *++s) { have_dig: nz++; + if (nf > DBL_DIG * 4) continue; if (c -= '0') { nf += nz; for (i = 1; i < nz; i++) -- 1.8.4.4