aboutsummaryrefslogtreecommitdiffstats
path: root/array.c
diff options
context:
space:
mode:
authorrhe <rhe@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-12-20 06:53:44 +0000
committerrhe <rhe@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-12-20 06:53:44 +0000
commit3d2a71470341f76fc3bf5c3fc930e9d1b5867b0e (patch)
tree4be181674e47eebed87689e62cb724197cd8afbd /array.c
parent0b04fe3596c106ed87c6ca148948f2ed0cbb4df9 (diff)
downloadruby-3d2a71470341f76fc3bf5c3fc930e9d1b5867b0e.tar.gz
array.c: do not resize to less than 0
Shrinking the Array from the block invoked by Array#select! or Array#reject! causes the Array to be a negative number size. Ensure that the resulting Array won't be smaller than 0. [ruby-core:78739] [Bug #13053] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57121 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'array.c')
-rw-r--r--array.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/array.c b/array.c
index b7ef04f397..580d1838a1 100644
--- a/array.c
+++ b/array.c
@@ -2886,13 +2886,15 @@ select_bang_ensure(VALUE a)
long len = RARRAY_LEN(ary);
long i1 = arg->len[0], i2 = arg->len[1];
- if (i2 < i1) {
+ if (i2 < len && i2 < i1) {
+ long tail = 0;
if (i1 < len) {
+ tail = len - i1;
RARRAY_PTR_USE(ary, ptr, {
- MEMMOVE(ptr + i2, ptr + i1, VALUE, len - i1);
+ MEMMOVE(ptr + i2, ptr + i1, VALUE, tail);
});
}
- ARY_SET_LEN(ary, len - i1 + i2);
+ ARY_SET_LEN(ary, i2 + tail);
}
return ary;
}