summaryrefslogtreecommitdiff
path: root/array.c
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-04-15 16:26:38 (GMT)
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-04-15 16:26:38 (GMT)
commitb59a158a1870000ef1db5acd52afa1b40e2c4fe6 (patch)
treea6c4bd607c4247f2f31aa8cb4c2266cf90ae28fd /array.c
parent72305d2531437e5303ac4d1c8756e81d35869149 (diff)
* array.c (rb_ary_sum): Don't yield same element twice.
Found by nagachika. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54609 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'array.c')
-rw-r--r--array.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/array.c b/array.c
index 5fe5800..f0a212d 100644
--- a/array.c
+++ b/array.c
@@ -5736,12 +5736,14 @@ rb_ary_sum(int argc, VALUE *argv, VALUE ary)
f = NUM2DBL(v);
c = 0.0;
+ goto has_float_value;
for (; i < RARRAY_LEN(ary); i++) {
double x, y, t;
e = RARRAY_AREF(ary, i);
if (block_given)
e = rb_yield(e);
if (RB_FLOAT_TYPE_P(e))
+ has_float_value:
x = RFLOAT_VALUE(e);
else if (FIXNUM_P(e))
x = FIX2LONG(e);
@@ -5763,10 +5765,12 @@ rb_ary_sum(int argc, VALUE *argv, VALUE ary)
v = DBL2NUM(f);
}
+ goto has_some_value;
for (; i < RARRAY_LEN(ary); i++) {
e = RARRAY_AREF(ary, i);
if (block_given)
e = rb_yield(e);
+ has_some_value:
v = rb_funcall(v, idPLUS, 1, e);
}
return v;