aboutsummaryrefslogtreecommitdiff
path: root/libexec
diff options
context:
space:
mode:
authorDavid Xu <davidxu@FreeBSD.org>2014-02-21 03:36:16 +0000
committerDavid Xu <davidxu@FreeBSD.org>2014-02-21 03:36:16 +0000
commit209782e06fd16c7330d789ff13502d5767a3a88f (patch)
treea08ed580c172bd9f152b4143ddc84dce824256e9 /libexec
parent182d7debb9f725cff2dbfe543ed82d4d9f988bb6 (diff)
downloadsrc-209782e06fd16c7330d789ff13502d5767a3a88f.tar.gz
src-209782e06fd16c7330d789ff13502d5767a3a88f.zip
Notes
Diffstat (limited to 'libexec')
-rw-r--r--libexec/rtld-elf/xmalloc.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/libexec/rtld-elf/xmalloc.c b/libexec/rtld-elf/xmalloc.c
index 3b3408c4e628..f8409e471169 100644
--- a/libexec/rtld-elf/xmalloc.c
+++ b/libexec/rtld-elf/xmalloc.c
@@ -72,14 +72,14 @@ void *
malloc_aligned(size_t size, size_t align)
{
void *mem, *res;
- uintptr_t x;
- size_t asize, r;
- r = round(sizeof(void *), align);
- asize = round(size, align) + r;
- mem = xmalloc(asize);
- x = (uintptr_t)mem;
- res = (void *)round(x, align);
+ if (align & (sizeof(void *) -1)) {
+ rtld_fdputstr(STDERR_FILENO, "Invalid alignment\n");
+ _exit(1);
+ }
+
+ mem = xmalloc(size + sizeof(void *) + align - 1);
+ res = (void *)round((uintptr_t)mem + sizeof(void *), align);
*(void **)((uintptr_t)res - sizeof(void *)) = mem;
return (res);
}