Skip to content
Snippets Groups Projects
Commit 1659ea4b authored by Ansgar Burchardt's avatar Ansgar Burchardt
Browse files

[release] debugallocator: use unsigned integer type for pointer arithmetic

ptrdiff_t is a signed integer type and so the expression
  (std::uintptr_t)(ptr) % page_size
could become a negative value. In this case the page_ptr would be the
address of the next page after the allocation.

This wrong behaviour could be observed on (32bit) PowerPC: here
ptr was 0xf78cfe00 and page_ptr was calculated as 0xf78d0000 instead
of the correct 0xf78c0000.
parent a7951dff
No related branches found
No related tags found
No related merge requests found
......@@ -9,6 +9,7 @@
#include <vector>
#include <iostream>
#include <cstring>
#include <cstdint>
#include <cstdlib>
#include <new>
#if HAVE_SYS_MMAN_H && HAVE_MPROTECT
......@@ -143,7 +144,7 @@ namespace Dune
// compute page address
void* page_ptr =
static_cast<void*>(
(char*)(ptr) - ((difference_type)(ptr) % page_size));
(char*)(ptr) - ((std::uintptr_t)(ptr) % page_size));
// search list
AllocationList::iterator it;
unsigned int i = 0;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment