diff --git a/src/libstd/vec.rs b/src/libstd/vec.rs index 055b0b92121af..c2aa4c234d1b7 100644 --- a/src/libstd/vec.rs +++ b/src/libstd/vec.rs @@ -186,7 +186,11 @@ pub fn with_capacity(capacity: uint) -> ~[T] { vec } else { let alloc = capacity * mem::nonzero_size_of::(); - let ptr = malloc_raw(alloc + mem::size_of::>()) as *mut Vec<()>; + let size = alloc + mem::size_of::>(); + if alloc / mem::nonzero_size_of::() != capacity || size < alloc { + fail!("vector size is too large: {}", capacity); + } + let ptr = malloc_raw(size) as *mut Vec<()>; (*ptr).alloc = alloc; (*ptr).fill = 0; cast::transmute(ptr)