Skip to content

Malloc should return address aligned to 8 bytes #100

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions test/malloc_compliance_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#include "base.hpp"
using umf_test::test;

#define ALLOC_MIN_ALIGNMENT 8

//------------------------------------------------------------------------
// Configurable defs
//------------------------------------------------------------------------
Expand Down Expand Up @@ -57,15 +59,9 @@ void malloc_compliance_test(umf_memory_pool_handle_t hPool) {
alloc_ptr_size[i] = rand_alloc_size(MAX_ALLOC_SIZE);
alloc_ptr[i] = umfPoolMalloc(hPool, alloc_ptr_size[i]);

#ifndef _WIN32 // TODO: explain why it fails on some Windows systems
// Supported under USE_WEAK_ALIGNMENT_RULES macro
// For compatibility, on 64-bit systems malloc should align to 16 bytes
size_t alignment =
(sizeof(intptr_t) > 4 && alloc_ptr_size[i] > 8) ? 16 : 8;
ASSERT_NE(addressIsAligned(alloc_ptr[i], alignment), 0)
ASSERT_NE(addressIsAligned(alloc_ptr[i], ALLOC_MIN_ALIGNMENT), 0)
<< "Malloc should return pointer that is suitably aligned so that "
"it may be assigned to a pointer to any type of object";
#endif

// Fill memory with a pattern ((id of the allocation) % 256)
ASSERT_NE(alloc_ptr[i], nullptr)
Expand Down