From: Waldemar Kozaczuk <[email protected]>
Committer: Nadav Har'El <[email protected]>
Branch: master

Refine tst-small-malloc to check alignment

Signed-off-by: Waldemar Kozaczuk <[email protected]>
Message-Id: <[email protected]>

---
diff --git a/core/mempool.cc b/core/mempool.cc
--- a/core/mempool.cc
+++ b/core/mempool.cc
@@ -1547,7 +1547,7 @@ static inline void* std_malloc(size_t size, size_t alignment)
         return libc_error_ptr<void *>(ENOMEM);
     void *ret;
     size_t minimum_size = std::max(size, memory::pool::min_object_size);
- if (minimum_size <= memory::pool::max_object_size && alignment <= minimum_size && smp_allocator) { + if (size <= memory::pool::max_object_size && alignment <= minimum_size && smp_allocator) {
         unsigned n = ilog2_roundup(minimum_size);
         ret = memory::malloc_pools[n].alloc();
ret = translate_mem_area(mmu::mem_area::main, mmu::mem_area::mempool,
diff --git a/tests/tst-small-malloc.cc b/tests/tst-small-malloc.cc
--- a/tests/tst-small-malloc.cc
+++ b/tests/tst-small-malloc.cc
@@ -12,13 +12,13 @@
 void test_malloc(size_t size) {
     void *addr = malloc(size);
     assert(addr);
-    free(addr);
+    assert(reinterpret_cast<uintptr_t>(addr) % 8 == 0);
 }

 void test_aligned_alloc(size_t alignment, size_t size) {
     void *addr = aligned_alloc(alignment, size);
     assert(addr);
-    free(addr);
+    assert(reinterpret_cast<uintptr_t>(addr) % alignment == 0);
 }

 int main() {

--
You received this message because you are subscribed to the Google Groups "OSv 
Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to