]> git.lizzy.rs Git - rust.git/commitdiff
collections: grow should use the overflow-checked reserve_additional
authorErick Tryzelaar <erick.tryzelaar@gmail.com>
Thu, 3 Jul 2014 15:40:08 +0000 (08:40 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Thu, 3 Jul 2014 19:54:52 +0000 (12:54 -0700)
src/libcollections/vec.rs

index 2ffc168f82c0eef4b4d77244a873ed3cd327d1a6..b8efaa78af3a9eb68de96705236140e20c23e3ac 100644 (file)
@@ -253,8 +253,7 @@ pub fn push_all(&mut self, other: &[T]) {
     /// assert_eq!(vec, vec!("hello", "world", "world"));
     /// ```
     pub fn grow(&mut self, n: uint, value: &T) {
-        let new_len = self.len() + n;
-        self.reserve(new_len);
+        self.reserve_additional(n);
         let mut i: uint = 0u;
 
         while i < n {