]> git.lizzy.rs Git - rust.git/commit
core: Fix size_hint for signed integer Range<T> iterators
authorUlrik Sverdrup <root@localhost>
Mon, 27 Apr 2015 11:27:24 +0000 (13:27 +0200)
committerUlrik Sverdrup <root@localhost>
Mon, 27 Apr 2015 19:14:43 +0000 (21:14 +0200)
commit95be21df477655131627def1943de73922b1f6a4
tree65e6126c8f3c6783d797b2c3a87ddf37ca2d902a
parentf191f924214aa1dcd342ada1d99775ccbb01ddd7
core: Fix size_hint for signed integer Range<T> iterators

There was an overflow bug in .size_hint() for signed iterators, which
produced an hilariously incorrect size or an overflow panic.

Incorrect size is a serious bug since the iterators are marked
ExactSizeIterator. (And leads to abort() on (-1i8..127).collect() when
the collection tries to preallocate too much).

All signed range iterators were affected.

> (-1i8..127).size_hint()
(18446744073709551488, Some(18446744073709551488))

Bug found using quickcheck.

Fixes #24851
src/libcore/iter.rs
src/libcoretest/iter.rs