summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--configure.ac6
-rw-r--r--fslsfonts.c12
2 files changed, 16 insertions, 2 deletions
diff --git a/configure.ac b/configure.ac
index fe1e011..bff7560 100644
--- a/configure.ac
+++ b/configure.ac
@@ -40,6 +40,12 @@ XORG_DEFAULT_OPTIONS
# Checks for pkg-config packages
PKG_CHECK_MODULES(FSLSFONTS, [xproto >= 7.0.25 libfs])
+# Checks for library functions
+AC_SEARCH_LIBS([reallocarray], [bsd])
+AS_IF([test "x$ac_cv_search_reallocarray" = "x-lbsd"],
+ [AC_CHECK_HEADERS([bsd/stdlib.h])])
+AC_CHECK_FUNCS([reallocarray])
+
AC_CONFIG_FILES([
Makefile
man/Makefile])
diff --git a/fslsfonts.c b/fslsfonts.c
index 3608e5a..ce8f7ab 100644
--- a/fslsfonts.c
+++ b/fslsfonts.c
@@ -53,6 +53,14 @@ in this Software without prior written authorization from The Open Group.
#include <stdlib.h>
#include <assert.h>
+#ifdef HAVE_BSD_STDLIB_H
+#include <bsd/stdlib.h>
+#endif
+
+#ifndef HAVE_REALLOCARRAY
+#define reallocarray(old, num, size) realloc(old, (num) * (size))
+#endif
+
#ifndef N_START
#define N_START 1000 /* Maximum # of fonts to start with */
#endif
@@ -267,8 +275,8 @@ get_list(const char *pattern)
else {
FontList *old_list = font_list;
- font_list = realloc(old_list, (font_cnt + (unsigned) available)
- * sizeof(FontList));
+ font_list = reallocarray(old_list, (font_cnt + (unsigned) available),
+ sizeof(FontList));
if (font_list == NULL) {
free(old_list);