Skip to content

Commit faf2a70

Browse files
committed
add extra alignment tests
1 parent 89f583a commit faf2a70

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

src/alloc-aligned.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,19 +51,19 @@ static void* mi_heap_malloc_zero_aligned_at(mi_heap_t* const heap, const size_t
5151
mi_assert(alignment > 0);
5252
if (mi_unlikely(alignment==0 || !_mi_is_power_of_two(alignment))) { // require power-of-two (see <https://en.cppreference.com/w/c/memory/aligned_alloc>)
5353
#if MI_DEBUG > 0
54-
_mi_error_message(EOVERFLOW, "aligned allocation requires the alignment to be a power-of-two (size %zu, alignment %zu)", size, alignment);
54+
_mi_error_message(EOVERFLOW, "aligned allocation requires the alignment to be a power-of-two (size %zu, alignment %zu)\n", size, alignment);
5555
#endif
5656
return NULL;
5757
}
5858
if (mi_unlikely(alignment > MI_ALIGNED_MAX)) { // we cannot align at a boundary larger than this (or otherwise we cannot find segment headers)
5959
#if MI_DEBUG > 0
60-
_mi_error_message(EOVERFLOW, "aligned allocation has a maximum alignment of %zu (size %zu, alignment %zu)", MI_ALIGNED_MAX, size, alignment);
60+
_mi_error_message(EOVERFLOW, "aligned allocation has a maximum alignment of %zu (size %zu, alignment %zu)\n", MI_ALIGNED_MAX, size, alignment);
6161
#endif
6262
return NULL;
6363
}
6464
if (mi_unlikely(size > PTRDIFF_MAX)) { // we don't allocate more than PTRDIFF_MAX (see <https://sourceware.org/ml/libc-announce/2019/msg00001.html>)
6565
#if MI_DEBUG > 0
66-
_mi_error_message(EOVERFLOW, "aligned allocation request is too large (size %zu, alignment %zu)", size, alignment);
66+
_mi_error_message(EOVERFLOW, "aligned allocation request is too large (size %zu, alignment %zu)\n", size, alignment);
6767
#endif
6868
return NULL;
6969
}

src/alloc-posix.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ mi_decl_restrict void* mi_pvalloc(size_t size) mi_attr_noexcept {
8585
mi_decl_restrict void* mi_aligned_alloc(size_t alignment, size_t size) mi_attr_noexcept {
8686
if (mi_unlikely((size&(alignment-1)) != 0)) { // C11 requires alignment>0 && integral multiple, see <https://en.cppreference.com/w/c/memory/aligned_alloc>
8787
#if MI_DEBUG > 0
88-
_mi_error_message(EOVERFLOW, "(mi_)aligned_alloc requires the size to be an integral multiple of the alignment (size %zu, alignment %zu)", size, alignment);
88+
_mi_error_message(EOVERFLOW, "(mi_)aligned_alloc requires the size to be an integral multiple of the alignment (size %zu, alignment %zu)\n", size, alignment);
8989
#endif
9090
return NULL;
9191
}

test/test-api.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,12 +162,18 @@ int main(void) {
162162
void* p;
163163
bool ok = true;
164164
for (int i = 1; i < 8 && ok; i++) {
165-
size_t align = 1UL << i;
165+
size_t align = (size_t)1 << i;
166166
p = mi_malloc_aligned(2*align, align);
167167
ok = (p != NULL && (uintptr_t)(p) % align == 0); mi_free(p);
168168
}
169169
result = ok;
170170
});
171+
CHECK_BODY("malloc-aligned7", {
172+
void* p = mi_malloc_aligned(1024,MI_ALIGNED_MAX); mi_free(p);
173+
});
174+
CHECK_BODY("malloc-aligned8", {
175+
void* p = mi_malloc_aligned(1024,2*MI_ALIGNED_MAX); mi_free(p);
176+
});
171177
CHECK_BODY("malloc-aligned-at1", {
172178
void* p = mi_malloc_aligned_at(48,32,0); result = (p != NULL && ((uintptr_t)(p) + 0) % 32 == 0); mi_free(p);
173179
});

0 commit comments

Comments
 (0)