From: Gabriel Corona Date: Mon, 4 May 2015 14:20:54 +0000 (+0200) Subject: [mc] Fix mm_fake_malloc() implementation X-Git-Tag: v3_12~732^2~23 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/f43bc484f697666583ba779d3adb325f1eee498b?hp=ea174fbe37a5a77f04c94335d63f298228505ae7 [mc] Fix mm_fake_malloc() implementation --- diff --git a/src/xbt/mmalloc/mm_legacy.c b/src/xbt/mmalloc/mm_legacy.c index cb12f56d80..2c1a0d5d9d 100644 --- a/src/xbt/mmalloc/mm_legacy.c +++ b/src/xbt/mmalloc/mm_legacy.c @@ -67,15 +67,17 @@ static uint64_t buffer[BUFFER_SIZE]; */ static void* mm_fake_malloc(size_t n) { + // How many uint64_t do w need? size_t count = n / sizeof(uint64_t); - if (n && 0xff) - count ++; - if (fake_alloc_index + count < BUFFER_SIZE) { - uint64_t* res = buffer + fake_alloc_index; - fake_alloc_index += count; - return res; - } - exit(127); + if (n % sizeof(uint64_t)) + count++; + // Check that we have enough availabel memory: + if (fake_alloc_index + count >= BUFFER_SIZE) + exit(127); + // Allocate it: + uint64_t* res = buffer + fake_alloc_index; + fake_alloc_index += count; + return res; } static void* mm_fake_calloc(size_t nmemb, size_t size)