summaryrefslogtreecommitdiff
path: root/enum.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-06-02 02:39:34 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-06-02 02:39:34 +0000
commit6bb70c11b344dee0739c6fb7bbf0ea124b5225b6 (patch)
tree707b0fceb6f5d2b988c3d513c94e709b5e780fd1 /enum.c
parentccc52902c00ac3758c2e20105bb33fae5a08583b (diff)
enum.c: mitigate overflows
* enum.c (enum_count): convert counters to Integer as unsigned long, instead of long, to mitigate overflows. [ruby-core:87348] [Bug #14805] * enum.c (ary_inject_op): ditto. * enum.c (each_with_index_i): ditto, instead of int. * enum.c (find_index_i, find_index_iter_i): ditto, instead of unsigned int. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63551 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'enum.c')
-rw-r--r--enum.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/enum.c b/enum.c
index c482e7b8ce..967bc6bada 100644
--- a/enum.c
+++ b/enum.c
@@ -218,7 +218,7 @@ enum_count(int argc, VALUE *argv, VALUE obj)
memo = MEMO_NEW(item, 0, 0);
rb_block_call(obj, id_each, 0, 0, func, (VALUE)memo);
- return LONG2NUM(memo->u3.cnt);
+ return ULONG2NUM(memo->u3.cnt);
}
static VALUE
@@ -286,7 +286,7 @@ find_index_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, memop))
ENUM_WANT_SVALUE();
if (rb_equal(i, memo->v2)) {
- MEMO_V1_SET(memo, UINT2NUM(memo->u3.cnt));
+ MEMO_V1_SET(memo, ULONG2NUM(memo->u3.cnt));
rb_iter_break();
}
memo->u3.cnt++;
@@ -299,7 +299,7 @@ find_index_iter_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, memop))
struct MEMO *memo = MEMO_CAST(memop);
if (RTEST(rb_yield_values2(argc, argv))) {
- MEMO_V1_SET(memo, UINT2NUM(memo->u3.cnt));
+ MEMO_V1_SET(memo, ULONG2NUM(memo->u3.cnt));
rb_iter_break();
}
memo->u3.cnt++;
@@ -693,7 +693,7 @@ ary_inject_op(VALUE ary, VALUE init, VALUE op)
if (FIXNUM_P(e)) {
n += FIX2LONG(e); /* should not overflow long type */
if (!FIXABLE(n)) {
- v = rb_big_plus(LONG2NUM(n), v);
+ v = rb_big_plus(ULONG2NUM(n), v);
n = 0;
}
}
@@ -2234,7 +2234,7 @@ each_with_index_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, memo))
{
long n = MEMO_CAST(memo)->u3.cnt++;
- return rb_yield_values(2, rb_enum_values_pack(argc, argv), INT2NUM(n));
+ return rb_yield_values(2, rb_enum_values_pack(argc, argv), ULONG2NUM(n));
}
/*