Bug #13053 closed
Array#select! can resize to negative size
Added by rhenium (Kazuki Yamaguchi) about 8 years ago.
Updated almost 8 years ago.
Description
Since Ruby 2.3 ([Feature #10714 ]), the following code cause the Array to be nagative number size.
ary = [ 1 , 2 , 3 , 4 , 5 ]
ary . select! { | i | ary . clear if i == 5 ; false }
p ary #=> []
p ary . size #=> -5
Status changed from Open to Closed
Applied in changeset r57121.
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 ]
Backport changed from 2.1: DONTNEED, 2.2: DONTNEED, 2.3: REQUIRED to 2.1: DONTNEED, 2.2: DONTNEED, 2.3: DONE
ruby_2_3 r58149 merged revision(s) 57121.
Also available in: Atom
PDF
Like 0
Like 0 Like 0