BumpPtrAllocator: use uintptr_t when aligning addresses to avoid undefined behaviour

In theory, alignPtr() could push a pointer beyond the end of the current slab, making
comparisons with that pointer undefined behaviour. Use an integer type to avoid this.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@216973 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Hans Wennborg
2014-09-02 21:51:35 +00:00
parent 891198b358
commit d52e9a143f
3 changed files with 26 additions and 23 deletions

View File

@@ -130,7 +130,7 @@ public:
void *MemBase = malloc(Size + Alignment - 1 + sizeof(void*));
// Find the slab start.
void *Slab = alignPtr((char *)MemBase + sizeof(void *), Alignment);
void *Slab = (void *)alignAddr((char*)MemBase + sizeof(void *), Alignment);
// Hold a pointer to the base so we can free the whole malloced block.
((void**)Slab)[-1] = MemBase;