summaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/util')
-rw-r--r--src/util/fontnames.c4
-rw-r--r--src/util/fontutil.c4
-rw-r--r--src/util/private.c2
-rw-r--r--src/util/replace.h4
4 files changed, 9 insertions, 5 deletions
diff --git a/src/util/fontnames.c b/src/util/fontnames.c
index 4460728..43eafc2 100644
--- a/src/util/fontnames.c
+++ b/src/util/fontnames.c
@@ -65,8 +65,8 @@ xfont2_make_font_names_record(unsigned size)
pFN->size = size;
if (size)
{
- pFN->length = malloc(size * sizeof(int));
- pFN->names = malloc(size * sizeof(char *));
+ pFN->length = mallocarray(size, sizeof(int));
+ pFN->names = mallocarray(size, sizeof(char *));
if (!pFN->length || !pFN->names) {
free(pFN->length);
free(pFN->names);
diff --git a/src/util/fontutil.c b/src/util/fontutil.c
index f7ac507..fd87d77 100644
--- a/src/util/fontutil.c
+++ b/src/util/fontutil.c
@@ -137,7 +137,7 @@ xfont2_query_text_extents(FontPtr pFont,
unsigned char defc[2];
int firstReal;
- charinfo = malloc(count * sizeof(xCharInfo *));
+ charinfo = mallocarray(count, sizeof(xCharInfo *));
if (!charinfo)
return FALSE;
encoding = TwoD16Bit;
@@ -303,7 +303,7 @@ add_range(fsRange *newrange,
/* Grow the list if necessary */
if (*nranges == 0 || *range == (fsRange *)0)
{
- *range = malloc(range_alloc_granularity * SIZEOF(fsRange));
+ *range = mallocarray(range_alloc_granularity, SIZEOF(fsRange));
*nranges = 0;
}
else if (!(*nranges % range_alloc_granularity))
diff --git a/src/util/private.c b/src/util/private.c
index 47c2699..b07a757 100644
--- a/src/util/private.c
+++ b/src/util/private.c
@@ -90,7 +90,7 @@ xfont2_font_set_private(FontPtr pFont, int n, pointer ptr)
return FALSE;
} else {
/* omg realloc */
- new = malloc ((n + 1) * sizeof (pointer));
+ new = reallocarray (NULL, (n + 1), sizeof (pointer));
if (!new)
return FALSE;
if (pFont->devPrivates)
diff --git a/src/util/replace.h b/src/util/replace.h
index 16be544..1a24820 100644
--- a/src/util/replace.h
+++ b/src/util/replace.h
@@ -41,6 +41,10 @@ extern _X_HIDDEN void *
reallocarray(void *optr, size_t nmemb, size_t size);
#endif
+#ifndef mallocarray
+#define mallocarray(n, s) reallocarray(NULL, n, s)
+#endif
+
#include <string.h>
#if defined(HAVE_LIBBSD) && defined(HAVE_STRLCPY)
#include <bsd/string.h> /* for strlcpy, strlcat */