From 65ddc0fbec22542f0c64baedc988af163a34d186 Mon Sep 17 00:00:00 2001 From: Christian Cunningham Date: Sat, 20 Aug 2022 13:49:11 -0700 Subject: Custom assertion messages --- src/mem/alloc.rs | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/mem/alloc.rs b/src/mem/alloc.rs index e06230d..66a8778 100644 --- a/src/mem/alloc.rs +++ b/src/mem/alloc.rs @@ -274,8 +274,8 @@ unsafe impl GlobalAlloc for GrandAllocator { let spacing: usize = (pool[3].ptr() as usize) - (pool[2].ptr() as usize); let diff: usize = (ptr as usize) - (pool[2].ptr() as usize); let index: usize = diff/spacing; - assert!(index < GRAND_ALLOC_SIZE); - assert_eq!(diff % spacing, 0); + assert!(index < GRAND_ALLOC_SIZE, "{} is out of the allocation bounds ({})", index, GRAND_ALLOC_SIZE); + assert_eq!(diff % spacing, 0, "{} is not aligned with the spacings and so it must not have been allocated by the Grand Allocator", diff % spacing); U8_GRAND_ALLOC.free(&mut pool[index]); }); } @@ -284,8 +284,8 @@ unsafe impl GlobalAlloc for GrandAllocator { let spacing: usize = (pool[3].ptr() as usize) - (pool[2].ptr() as usize); let diff: usize = (ptr as usize) - (pool[2].ptr() as usize); let index: usize = diff/spacing; - assert!(index < GRAND_ALLOC_SIZE); - assert_eq!(diff % spacing, 0); + assert!(index < GRAND_ALLOC_SIZE, "{} is out of the allocation bounds ({})", index, GRAND_ALLOC_SIZE); + assert_eq!(diff % spacing, 0, "{} is not aligned with the spacings and so it must not have been allocated by the Grand Allocator", diff % spacing); U16_GRAND_ALLOC.free(&mut pool[index]); }); } @@ -294,8 +294,8 @@ unsafe impl GlobalAlloc for GrandAllocator { let spacing: usize = (pool[3].ptr() as usize) - (pool[2].ptr() as usize); let diff: usize = (ptr as usize) - (pool[2].ptr() as usize); let index: usize = diff/spacing; - assert!(index < GRAND_ALLOC_SIZE); - assert_eq!(diff % spacing, 0); + assert!(index < GRAND_ALLOC_SIZE, "{} is out of the allocation bounds ({})", index, GRAND_ALLOC_SIZE); + assert_eq!(diff % spacing, 0, "{} is not aligned with the spacings and so it must not have been allocated by the Grand Allocator", diff % spacing); U32_GRAND_ALLOC.free(&mut pool[index]); }); } @@ -304,8 +304,8 @@ unsafe impl GlobalAlloc for GrandAllocator { let spacing: usize = (pool[3].ptr() as usize) - (pool[2].ptr() as usize); let diff: usize = (ptr as usize) - (pool[2].ptr() as usize); let index: usize = diff/spacing; - assert!(index < GRAND_ALLOC_SIZE); - assert_eq!(diff % spacing, 0); + assert!(index < GRAND_ALLOC_SIZE, "{} is out of the allocation bounds ({})", index, GRAND_ALLOC_SIZE); + assert_eq!(diff % spacing, 0, "{} is not aligned with the spacings and so it must not have been allocated by the Grand Allocator", diff % spacing); U64_GRAND_ALLOC.free(&mut pool[index]); }); } @@ -314,8 +314,8 @@ unsafe impl GlobalAlloc for GrandAllocator { let spacing: usize = (pool[3].ptr() as usize) - (pool[2].ptr() as usize); let diff: usize = (ptr as usize) - (pool[2].ptr() as usize); let index: usize = diff/spacing; - assert!(index < GRAND_ALLOC_SIZE); - assert_eq!(diff % spacing, 0); + assert!(index < GRAND_ALLOC_SIZE, "{} is out of the allocation bounds ({})", index, GRAND_ALLOC_SIZE); + assert_eq!(diff % spacing, 0, "{} is not aligned with the spacings and so it must not have been allocated by the Grand Allocator", diff % spacing); U128_GRAND_ALLOC.free(&mut pool[index]); }); } @@ -324,8 +324,8 @@ unsafe impl GlobalAlloc for GrandAllocator { let spacing: usize = (pool[3].ptr() as usize) - (pool[2].ptr() as usize); let diff: usize = (ptr as usize) - (pool[2].ptr() as usize); let index: usize = diff/spacing; - assert!(index < GRAND_ALLOC_SIZE); - assert_eq!(diff % spacing, 0); + assert!(index < GRAND_ALLOC_SIZE, "{} is out of the allocation bounds ({})", index, GRAND_ALLOC_SIZE); + assert_eq!(diff % spacing, 0, "{} is not aligned with the spacings and so it must not have been allocated by the Grand Allocator", diff % spacing); U256_GRAND_ALLOC.free(&mut pool[index]); }); } -- cgit v1.2.1