AC_CHECK_FUNCS([dnl
pow dnl Used only by "examples/manual/expr"
setlocale dnl Needed only if NLS is enabled
+reallocarr dnl NetBSD function. Use reallocarray if not available.
reallocarray dnl OpenBSD function. We have replacement if not available.
])
void *allocate_array (int size, size_t element_size)
{
void *mem;
-#if HAVE_REALLOCARRAY
+#if HAVE_REALLOCARR
+ mem = NULL;
+ if (reallocarr(&mem, (size_t) size, element_size))
+ flexfatal (_
+ ("memory allocation failed in allocate_array()"));
+
+ return mem;
+#elif HAVE_REALLOCARRAY
/* reallocarray has built-in overflow detection */
mem = reallocarray(NULL, (size_t) size, element_size);
#else
void *reallocate_array (void *array, int size, size_t element_size)
{
void *new_array;
-#if HAVE_REALLOCARRAY
+#if HAVE_REALLOCARR
+ if (reallocarr(&array, (size_t) size, element_size))
+ flexfatal (_("attempt to increase array size failed"));
+
+ return array;
+#elif HAVE_REALLOCARRAY
/* reallocarray has built-in overflow detection */
new_array = reallocarray(array, (size_t) size, element_size);
#else