Skip to content

Commit 5948d8a

Browse files
tmmcguireemberian
authored andcommitted
Ensure reverse_part does not access outside given vector
1 parent 2264c79 commit 5948d8a

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/libcore/vec.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1450,6 +1450,9 @@ pub fn reverse<T>(v: &mut [T]) {
14501450
*
14511451
* Reverse the elements in the vector between `start` and `end - 1`.
14521452
*
1453+
* If either start or end do not represent valid positions in the vector, the
1454+
* vector is returned unchanged.
1455+
*
14531456
* # Arguments
14541457
*
14551458
* * `v` - The mutable vector to be modified
@@ -1469,13 +1472,10 @@ pub fn reverse<T>(v: &mut [T]) {
14691472
* ~~~
14701473
*
14711474
* `v` now contains `[1,4,3,2,5]`.
1472-
*
1473-
* # Safety note
1474-
*
1475-
* Behavior is undefined if `start` or `end` do not represent valid
1476-
* positions in `v`.
14771475
*/
14781476
pub fn reverse_part<T>(v: &mut [T], start: uint, end : uint) {
1477+
let sz = v.len();
1478+
if start >= sz || end > sz { return; }
14791479
let mut i = start;
14801480
let mut j = end - 1;
14811481
while i < j {

0 commit comments

Comments
 (0)