From a2fc726a6225ceb94dba367cf5acfe597ce11d74 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Thu, 29 Nov 2018 21:25:44 +0100 Subject: A bunch of stuff MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- allocn.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'allocn.c') diff --git a/allocn.c b/allocn.c index d54542c..ce4fbad 100644 --- a/allocn.c +++ b/allocn.c @@ -15,11 +15,10 @@ alloc_size_product(int *errp, size_t n, va_list ap) n = va_arg(ap, size_t); if (!n) break; - if (n >= SIZE_MAX / prod) { + if (LIBSIMPLE_UMUL_OVERFLOW_NONZERO(n, prod, &prod, SIZE_MAX)) { *errp = ENOMEM; return 0; } - prod *= n; } return prod; } @@ -62,6 +61,15 @@ libsimple_vposix_memalignzn(void **memptr, int clear, size_t alignment, size_t n return ret; } +#ifdef LIBSIMPLE_HAVE_ALIGNED_REALLOC +void * +libsimple_valigned_reallocn(void *ptr, size_t alignment, size_t n, va_list ap) /* TODO test (aligned_reallocn) */ +{ + n = alloc_size_product(&errno, n, ap); + return !n ? NULL : aligned_realloc(ptr, alignment, n); +} +#endif + #else #include "test.h" -- cgit v1.2.3-70-g09d2