From 5e98a2b1a83d3575fd787a16cdfb55b7df99d772 Mon Sep 17 00:00:00 2001 From: Roy Marples Date: Fri, 6 May 2016 20:51:37 +0000 Subject: [PATCH] Use libc reallocarray in eloop if we have it. --- configure | 2 ++ eloop.c | 8 +++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/configure b/configure index 457ff082..b5af0655 100755 --- a/configure +++ b/configure @@ -917,6 +917,8 @@ fi if [ "$REALLOCARRAY" = no ]; then echo "COMPAT_SRCS+= compat/reallocarray.c" >>$CONFIG_MK echo "#include \"compat/reallocarray.h\"">>$CONFIG_H +else + echo "#define HAVE_REALLOCARRAY" >>$CONFIG_H fi if [ -z "$POLL" ]; then diff --git a/eloop.c b/eloop.c index 13d79642..c72f0c5b 100644 --- a/eloop.c +++ b/eloop.c @@ -181,10 +181,11 @@ struct eloop { int exitcode; }; +#ifdef HAVE_REALLOCARRAY +#define eloop_realloca reallocarray +#else /* Handy routing to check for potential overflow. - * reallocarray(3) and reallocarr(3) are not portable and this - * implementation is smaller than using either in libc in - * the final binary size. */ + * reallocarray(3) and reallocarr(3) are not portable. */ #define SQRT_SIZE_MAX (((size_t)1) << (sizeof(size_t) * CHAR_BIT / 2)) static void * eloop_realloca(void *ptr, size_t n, size_t size) @@ -196,6 +197,7 @@ eloop_realloca(void *ptr, size_t n, size_t size) } return realloc(ptr, n * size); } +#endif #ifdef HAVE_POLL static void -- 2.47.3