diff options
| author | bors <bors@rust-lang.org> | 2015-05-12 04:17:30 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2015-05-12 04:17:30 +0000 |
| commit | a90453a178069b890aa3877009fa99968dc85c09 (patch) | |
| tree | 49b97d0b5f6741912f13ccd6e7f148b951fe73b1 /src/liballoc | |
| parent | 4b88e8f63eeaf557c916a0a1e73150b028c44c52 (diff) | |
| parent | 28b923c4770b23c4b7b892f2161e020770d1706f (diff) | |
| download | rust-a90453a178069b890aa3877009fa99968dc85c09.tar.gz rust-a90453a178069b890aa3877009fa99968dc85c09.zip | |
Auto merge of #25320 - steveklabnik:rollup, r=steveklabnik
- Successful merges: #25254, #25272, #25278, #25282, #25283, #25288, #25292, #25302, #25304, #25314 - Failed merges:
Diffstat (limited to 'src/liballoc')
| -rw-r--r-- | src/liballoc/heap.rs | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/liballoc/heap.rs b/src/liballoc/heap.rs index 83795a24c81..e155dc86f32 100644 --- a/src/liballoc/heap.rs +++ b/src/liballoc/heap.rs @@ -8,6 +8,15 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +use core::{isize, usize}; + +#[inline(always)] +fn check_size_and_alignment(size: usize, align: usize) { + debug_assert!(size != 0); + debug_assert!(size <= isize::MAX as usize, "Tried to allocate too much: {} bytes", size); + debug_assert!(usize::is_power_of_two(align), "Invalid alignment of allocation: {}", align); +} + // FIXME: #13996: mark the `allocate` and `reallocate` return value as `noalias` /// Return a pointer to `size` bytes of memory aligned to `align`. @@ -19,6 +28,7 @@ /// size on the platform. #[inline] pub unsafe fn allocate(size: usize, align: usize) -> *mut u8 { + check_size_and_alignment(size, align); imp::allocate(size, align) } @@ -38,6 +48,7 @@ pub unsafe fn allocate(size: usize, align: usize) -> *mut u8 { /// any value in range_inclusive(requested_size, usable_size). #[inline] pub unsafe fn reallocate(ptr: *mut u8, old_size: usize, size: usize, align: usize) -> *mut u8 { + check_size_and_alignment(size, align); imp::reallocate(ptr, old_size, size, align) } @@ -56,6 +67,7 @@ pub unsafe fn reallocate(ptr: *mut u8, old_size: usize, size: usize, align: usiz #[inline] pub unsafe fn reallocate_inplace(ptr: *mut u8, old_size: usize, size: usize, align: usize) -> usize { + check_size_and_alignment(size, align); imp::reallocate_inplace(ptr, old_size, size, align) } |
