From d1417176a35d27ffb8da0ffb1e33154163b6eeb2 Mon Sep 17 00:00:00 2001 From: DJ Delorie Date: Tue, 21 Mar 2023 00:46:43 -0400 Subject: aligned_alloc: conform to C17 This patch adds the strict checking for power-of-two alignments in aligned_alloc(), and updates the manual accordingly. Reviewed-by: Carlos O'Donell --- malloc/malloc-debug.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'malloc/malloc-debug.c') diff --git a/malloc/malloc-debug.c b/malloc/malloc-debug.c index 3867d15698..da9d2340d3 100644 --- a/malloc/malloc-debug.c +++ b/malloc/malloc-debug.c @@ -299,7 +299,14 @@ __debug_memalign (size_t alignment, size_t bytes) return _debug_mid_memalign (alignment, bytes, RETURN_ADDRESS (0)); } strong_alias (__debug_memalign, memalign) -strong_alias (__debug_memalign, aligned_alloc) +static void * +__debug_aligned_alloc (size_t alignment, size_t bytes) +{ + if (!powerof2 (alignment) || alignment == 0) + return NULL; + return _debug_mid_memalign (alignment, bytes, RETURN_ADDRESS (0)); +} +strong_alias (__debug_aligned_alloc, aligned_alloc) static void * __debug_pvalloc (size_t bytes) -- cgit v1.2.3