Skip to content

Commit a03ba01

Browse files
committed
Use malloc if posix_memalign is unavailable
1 parent 8de74af commit a03ba01

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/crypto/ocb.cc

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,17 @@ ae_ctx* ae_allocate(void *misc)
630630
#if (__SSE2__ && !_M_X64 && !_M_AMD64 && !__amd64__)
631631
p = _mm_malloc(sizeof(ae_ctx),16);
632632
#elif (__ALTIVEC__ && !__PPC64__)
633-
if (posix_memalign(&p,16,sizeof(ae_ctx)) != 0) p = NULL;
633+
#if HAVE_POSIX_MEMALIGN
634+
if (posix_memalign(&p,16,sizeof(ae_ctx)) != 0) p = NULL;
635+
#else
636+
// Probably building on OS X, which provides an aligned malloc()
637+
if (!(p = malloc(sizeof(ae_ctx)))) p = NULL;
638+
if ((uintptr_t)p & 0xF) {
639+
// We didn't get an aligned pointer (should never happen)
640+
free(p);
641+
p = NULL;
642+
}
643+
#endif
634644
#else
635645
p = malloc(sizeof(ae_ctx));
636646
#endif

0 commit comments

Comments
 (0)