/* Allow non-malloc() allocations as long as no malloc_impl is provided. */
if (malloc_impl == CRYPTO_malloc) {
#if defined(_BSD_SOURCE) || (defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 200112L)
- int memalign_ret;
void *ret;
/* posix_memalign() requires alignment to be at least sizeof(void *) */
if (alignment < sizeof(void *))
alignment = sizeof(void *);
- if ((memalign_ret = posix_memalign(&ret, alignment, num))) {
- ret = NULL;
- switch (memalign_ret) {
- case EINVAL:
- ossl_report_alloc_err_inv(file, line);
- break;
- case ENOMEM:
- ossl_report_alloc_err(file, line);
- break;
- }
+ if (posix_memalign(&ret, alignment, num) == 0) {
+ *freeptr = ret;
+ return ret;
}
- *freeptr = ret;
- return ret;
#endif
}
{ SIZE_MAX / 8 + 9, 8, 64, EXP_NONNULL, EXP_INT_OF },
/*
- * posix_memalign expected to fail with ENOMEM, while the open-coded
- * implementation tries to alloc size + alignment, which should fail
- * on integer overflow.
+ * the open-coded implementation tries to alloc size + alignment,
+ * which should fail on integer overflow.
*/
- { 1, SIZE_MAX / 2 + 2, SIZE_MAX / 2 + 1,
-#if (defined(_BSD_SOURCE) \
- || (defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 200112L)) \
- && !USE_CUSTOM_ALLOC_FNS
- EXP_OOM, EXP_OOM
-#else
- EXP_INT_OF, EXP_INT_OF
-#endif
- },
+ { 1, SIZE_MAX - 32767, 65536, EXP_INT_OF, EXP_INT_OF },
};
static int secure_memory_is_secure;