Skip to content

Commit

Permalink
auto merge of #10417 : cmr/rust/vec_overflow, r=huonw
Browse files Browse the repository at this point in the history
Fixes #10271
  • Loading branch information
bors committed Nov 11, 2013
2 parents 4059b5c + a46b2b8 commit 4d9b95f
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/libstd/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,11 @@ pub fn with_capacity<T>(capacity: uint) -> ~[T] {
vec
} else {
let alloc = capacity * mem::nonzero_size_of::<T>();
let ptr = malloc_raw(alloc + mem::size_of::<Vec<()>>()) as *mut Vec<()>;
let size = alloc + mem::size_of::<Vec<()>>();
if alloc / mem::nonzero_size_of::<T>() != 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)
Expand Down

0 comments on commit 4d9b95f

Please sign in to comment.