aboutsummaryrefslogtreecommitdiffstats
path: root/array.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-02-18 04:23:20 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-02-18 04:23:20 +0000
commit2e571343175bec9b34ecd729dd6fe56b7922adbb (patch)
tree7966e8308cb1825df565b602eb197439f5a993aa /array.c
parent05e3ecbf8321064534fd3f73a36c70a6612cdeee (diff)
downloadruby-2e571343175bec9b34ecd729dd6fe56b7922adbb.tar.gz
array.c: check if numeric
* array.c (finish_exact_sum): add 0 and the initial value to check if the latter is numeric. [ruby-core:79572] [Bug #13222] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57651 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'array.c')
-rw-r--r--array.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/array.c b/array.c
index d9d6bdbf87..182046856c 100644
--- a/array.c
+++ b/array.c
@@ -5734,7 +5734,7 @@ rb_ary_dig(int argc, VALUE *argv, VALUE self)
}
static inline VALUE
-finish_exact_sum(long n, VALUE r, VALUE v)
+finish_exact_sum(long n, VALUE r, VALUE v, int z)
{
if (n != 0)
v = rb_fix_plus(LONG2FIX(n), v);
@@ -5747,6 +5747,9 @@ finish_exact_sum(long n, VALUE r, VALUE v)
else
v = rb_rational_plus(r, v);
}
+ else if (!n && z) {
+ v = rb_fix_plus(LONG2FIX(0), v);
+ }
return v;
}
@@ -5831,11 +5834,11 @@ rb_ary_sum(int argc, VALUE *argv, VALUE ary)
else
goto not_exact;
}
- v = finish_exact_sum(n, r, v);
+ v = finish_exact_sum(n, r, v, argc!=0);
return v;
not_exact:
- v = finish_exact_sum(n, r, v);
+ v = finish_exact_sum(n, r, v, i!=0);
if (RB_FLOAT_TYPE_P(e)) {
/*