]> granicus.if.org Git - flex/commitdiff
scanner: Use reallocarr() when available.
authorThomas Klausner <wiz@NetBSD.org>
Fri, 19 May 2017 08:22:44 +0000 (10:22 +0200)
committerWill Estes <westes575@gmail.com>
Fri, 19 May 2017 11:29:15 +0000 (07:29 -0400)
NetBSD had a crash during build. Since the provided substitute for
reallocarray() wasn't working, use NetBSD's reallocarr(). Let
configure choose that function whenever it is available. Use
reallocarray if available. Still fallback if neither is available.

Fixes #219

configure.ac
src/misc.c

index 55e774b014be39c58682e45c16adb411805f9f96..d0f3b7da232465e95514eb7f49e8069b8de61044 100644 (file)
@@ -166,6 +166,7 @@ strtol dnl
 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.
 ])
 
index ef27833c3ea71a0da8779b5c5e38e44a61c2180c..39483ea8119ba761523f44271ea1e5bbe7fdff07 100644 (file)
@@ -142,7 +142,14 @@ void add_action (const char *new_text)
 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
@@ -659,7 +666,12 @@ char   *readable_form (int c)
 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