diff options
author | Andrea Fioraldi <andreafioraldi@gmail.com> | 2019-12-12 22:18:52 +0100 |
---|---|---|
committer | Andrea Fioraldi <andreafioraldi@gmail.com> | 2019-12-12 22:18:52 +0100 |
commit | d40b6703885b80cbea13ecbb58b48b01ac96b2b0 (patch) | |
tree | 460b91b29911cea95249022849fecb0142fb3641 /libdislocator | |
parent | 01f0af64dac97edd6fdcd1e91c94f8454f8bdb2c (diff) | |
download | AFLplusplus-d40b6703885b80cbea13ecbb58b48b01ac96b2b0.tar.gz |
solve #134
Diffstat (limited to 'libdislocator')
-rw-r--r-- | libdislocator/libdislocator.so.c | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/libdislocator/libdislocator.so.c b/libdislocator/libdislocator.so.c index d92a6985..10ea0a61 100644 --- a/libdislocator/libdislocator.so.c +++ b/libdislocator/libdislocator.so.c @@ -340,7 +340,7 @@ void* realloc(void* ptr, size_t len) { int posix_memalign(void** ptr, size_t align, size_t len) { - if (*ptr == NULL) return EINVAL; + // if (*ptr == NULL) return EINVAL; // (andrea) Why? I comment it out for now if ((align % 2) || (align % sizeof(void*))) return EINVAL; if (len == 0) { @@ -348,12 +348,15 @@ int posix_memalign(void** ptr, size_t align, size_t len) { return 0; } + + size_t rem = len % align; + if (rem) len += align - rem; + + *ptr = __dislocator_alloc(len); - if (align >= 4 * sizeof(size_t)) len += align - 1; + if (*ptr && len) memset(*ptr, ALLOC_CLOBBER, len); - *ptr = malloc(len); - - DEBUGF("posix_memalign(%p %zu, %zu)", ptr, align, len); + DEBUGF("posix_memalign(%p %zu, %zu) [*ptr = %p]", ptr, align, len, *ptr); return 0; |