summaryrefslogtreecommitdiff
path: root/malloc.c
diff options
context:
space:
mode:
authorIvan Maidanski <ivmai@mail.ru>2023-03-24 22:57:26 +0300
committerIvan Maidanski <ivmai@mail.ru>2023-03-24 22:57:26 +0300
commit4f18441368365d056d23ca62efdc7d9920971893 (patch)
tree4415d23c3a86d1d335848e559209ca2af950fe56 /malloc.c
parent3a6a58e899ccd5336bb2cb58417a45c14d4c7c0f (diff)
downloadbdwgc-4f18441368365d056d23ca62efdc7d9920971893.tar.gz
Prevent zero size passed GC_alloc_large if aligned allocation
(fix of commit ba137368d) * malloc.c (GC_generic_malloc_aligned): If lb is zero then set it to 1 (before rounding it up and converting to granules). * malloc.c [THREADS] (GC_generic_malloc_aligned): Add assertion to ensure GRANULES_TO_WORDS(lg)-2 is not negative.
Diffstat (limited to 'malloc.c')
-rw-r--r--malloc.c2
1 files changed, 2 insertions, 0 deletions
diff --git a/malloc.c b/malloc.c
index 8e9b6cce..b1a14778 100644
--- a/malloc.c
+++ b/malloc.c
@@ -229,6 +229,7 @@ GC_INNER void * GC_generic_malloc_aligned(size_t lb, int k, unsigned flags,
size_t lb_rounded;
GC_bool init;
+ if (EXPECT(0 == lb, FALSE)) lb = 1;
lg = ALLOC_REQUEST_GRANS(lb);
lb_rounded = GRANULES_TO_BYTES(lg);
init = GC_obj_kinds[k].ok_init;
@@ -244,6 +245,7 @@ GC_INNER void * GC_generic_malloc_aligned(size_t lb, int k, unsigned flags,
BZERO(result, HBLKSIZE * OBJ_SZ_TO_BLOCKS(lb_rounded));
} else {
# ifdef THREADS
+ GC_ASSERT(GRANULES_TO_WORDS(lg) >= 2);
/* Clear any memory that might be used for GC descriptors */
/* before we release the lock. */
((word *)result)[0] = 0;