summaryrefslogtreecommitdiff
path: root/fslsfonts.c
diff options
context:
space:
mode:
authorAlan Coopersmith <alan.coopersmith@oracle.com>2022-08-13 14:50:51 -0700
committerAlan Coopersmith <alan.coopersmith@oracle.com>2022-08-13 15:35:32 -0700
commit7e039ed98ad9ef4083a01d3e5a03e54302706550 (patch)
treea4b21509e6bcf2dcccce64c8387964668441c085 /fslsfonts.c
parent23fa33d7061a2bba7f0732ea0c8c324a560a65d3 (diff)
Use reallocarray() if it is available in libc or libbsd
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Diffstat (limited to 'fslsfonts.c')
-rw-r--r--fslsfonts.c12
1 files changed, 10 insertions, 2 deletions
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);