1.修改 host-flex-2.6.4/configure.ac:
@@ -25,8 +25,10 @@
# autoconf requirements and initialization
AC_INIT([the fast lexical analyser generator],[2.6.4],[flex-help@lists.sourceforge.net],[flex])
+AC_PREREQ([2.60])
AC_CONFIG_SRCDIR([src/scan.l])
AC_CONFIG_AUX_DIR([build-aux])
+AC_USE_SYSTEM_EXTENSIONS
LT_INIT
AM_INIT_AUTOMAKE([1.15 -Wno-portability foreign std-options dist-lzip parallel-tests subdir-objects])
AC_CONFIG_HEADER([src/config.h])
@@ -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.
])
2.修改 host-flex-2.6.4/src/misc.c:
@@ -142,7 +142,14 @@ void add_action (const char *new_text)
void *allocate_array (int size, size_t element_size)
{
- void *mem;
+ void *new_array;
-#if HAVE_REALLOCARRAY
+#if HAVE_REALLOCARR
-
- /* reallocarray has built-in overflow detection */
- mem = reallocarray(NULL, (size_t) size, element_size);
+ new_array = NULL;
+ if (reallocarr(&new_array, (size_t) size, element_size))
+ flexfatal (_("memory allocation failed in allocate_array()"));
#else
+# if HAVE_REALLOCARRAY
+ new_array = reallocarray(NULL, (size_t) size, element_size);
+# else
+ /* Do manual overflow detection */
size_t num_bytes = (size_t) size * element_size;
- mem = (size && SIZE_MAX / (size_t) size < element_size) ? NULL :
+ new_array = (size && SIZE_MAX / (size_t) size < element_size) ? NULL :
malloc(num_bytes);
+# endif
+ if (!new_array)
+ flexfatal (_("memory allocation failed in allocate_array()"));
#endif
- if (!mem)
- flexfatal (_
- ("memory allocation failed in allocate_array()"));
-
- return mem;
+ return new_array;
}
@@ -667,21 +664,21 @@ void *reallocate_array (void *array, int size, size_t element_size)
void *reallocate_array (void *array, int size, size_t element_size)
{
void *new_array;
-#if HAVE_REALLOCARRAY
+#if HAVE_REALLOCARR
+ new_array = array;
+ if (reallocarr(&new_array, (size_t) size, element_size))
+ flexfatal (_("attempt to increase array size failed"));
- /* reallocarray has built-in overflow detection */
- new_array = reallocarray(array, (size_t) size, element_size);
#else
+# if HAVE_REALLOCARRAY
+ new_array = reallocarray(array, (size_t) size, element_size);
+# else
+ /* Do manual overflow detection */
size_t num_bytes = (size_t) size * element_size;
new_array = (size && SIZE_MAX / (size_t) size < element_size) ? NULL :
realloc(array, num_bytes);
-#endif
+# endif
if (!new_array)
flexfatal (_("attempt to increase array size failed"));
+#endif
return new_array;
}