We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 4059b5c + a46b2b8 commit 4d9b95fCopy full SHA for 4d9b95f
src/libstd/vec.rs
@@ -186,7 +186,11 @@ pub fn with_capacity<T>(capacity: uint) -> ~[T] {
186
vec
187
} else {
188
let alloc = capacity * mem::nonzero_size_of::<T>();
189
- let ptr = malloc_raw(alloc + mem::size_of::<Vec<()>>()) as *mut Vec<()>;
+ let size = alloc + mem::size_of::<Vec<()>>();
190
+ if alloc / mem::nonzero_size_of::<T>() != capacity || size < alloc {
191
+ fail!("vector size is too large: {}", capacity);
192
+ }
193
+ let ptr = malloc_raw(size) as *mut Vec<()>;
194
(*ptr).alloc = alloc;
195
(*ptr).fill = 0;
196
cast::transmute(ptr)
0 commit comments