summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlan Coopersmith <alan.coopersmith@oracle.com>2019-08-03 19:09:19 -0700
committerAlan Coopersmith <alan.coopersmith@oracle.com>2019-08-03 19:31:14 -0700
commitf54470dab5b392380df61a22b4b4bef685b6cee2 (patch)
tree561d2a367f295f3fe53f72712b3b3f3d1011ec18 /src
parent27207d35d4b4bbd5d2b2c5f7e13a61ea43d04a4a (diff)
Convert multiplying realloc calls to use reallocarray instead
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Diffstat (limited to 'src')
-rw-r--r--src/FreeType/ftfuncs.c2
-rw-r--r--src/fontfile/bitsource.c3
-rw-r--r--src/fontfile/catalogue.c4
-rw-r--r--src/fontfile/fontdir.c2
-rw-r--r--src/fontfile/fontscale.c3
-rw-r--r--src/fontfile/renderers.c3
-rw-r--r--src/stubs/atom.c3
-rw-r--r--src/util/fontnames.c5
-rw-r--r--src/util/fontutil.c5
-rw-r--r--src/util/private.c3
10 files changed, 21 insertions, 12 deletions
diff --git a/src/FreeType/ftfuncs.c b/src/FreeType/ftfuncs.c
index bc41bdf..f86d8dd 100644
--- a/src/FreeType/ftfuncs.c
+++ b/src/FreeType/ftfuncs.c
@@ -2124,7 +2124,7 @@ restrict_code_range_by_str(int count,unsigned short *refFirstCol,
#endif
nRanges++;
oldRanges = ranges;
- ranges = realloc(ranges, nRanges*sizeof(*ranges));
+ ranges = reallocarray(ranges, nRanges, sizeof(*ranges));
if (NULL == ranges) {
free(oldRanges);
break;
diff --git a/src/fontfile/bitsource.c b/src/fontfile/bitsource.c
index 3a6a20f..8437d44 100644
--- a/src/fontfile/bitsource.c
+++ b/src/fontfile/bitsource.c
@@ -32,6 +32,7 @@ in this Software without prior written authorization from The Open Group.
#include <config.h>
#endif
#include "libxfontint.h"
+#include "src/util/replace.h"
#include <X11/fonts/fntfilst.h>
BitmapSourcesRec FontFileBitmapSources;
@@ -49,7 +50,7 @@ FontFileRegisterBitmapSource (FontPathElementPtr fpe)
if (FontFileBitmapSources.count == FontFileBitmapSources.size)
{
newsize = FontFileBitmapSources.size + 4;
- new = realloc (FontFileBitmapSources.fpe, newsize * sizeof *new);
+ new = reallocarray (FontFileBitmapSources.fpe, newsize, sizeof *new);
if (!new)
return FALSE;
FontFileBitmapSources.size = newsize;
diff --git a/src/fontfile/catalogue.c b/src/fontfile/catalogue.c
index 2087232..5df01c2 100644
--- a/src/fontfile/catalogue.c
+++ b/src/fontfile/catalogue.c
@@ -35,6 +35,7 @@
#include <sys/stat.h>
#include <dirent.h>
#include <unistd.h>
+#include "src/util/replace.h"
static const char CataloguePrefix[] = "catalogue:";
@@ -64,7 +65,8 @@ CatalogueAddFPE (CataloguePtr cat, FontPathElementPtr fpe)
else
cat->fpeAlloc *= 2;
- new = realloc(cat->fpeList, cat->fpeAlloc * sizeof(FontPathElementPtr));
+ new = reallocarray(cat->fpeList, cat->fpeAlloc,
+ sizeof(FontPathElementPtr));
if (new == NULL)
return AllocError;
diff --git a/src/fontfile/fontdir.c b/src/fontfile/fontdir.c
index 2cc97b4..c07222f 100644
--- a/src/fontfile/fontdir.c
+++ b/src/fontfile/fontdir.c
@@ -185,7 +185,7 @@ FontFileAddEntry(FontTablePtr table, FontEntryPtr prototype)
directory that we should just give up before we overflow. */
return NULL;
newsize = table->size + 100;
- entry = realloc(table->entries, newsize * sizeof(FontEntryRec));
+ entry = reallocarray(table->entries, newsize, sizeof(FontEntryRec));
if (!entry)
return (FontEntryPtr)0;
table->size = newsize;
diff --git a/src/fontfile/fontscale.c b/src/fontfile/fontscale.c
index bbc8e10..7fcaba8 100644
--- a/src/fontfile/fontscale.c
+++ b/src/fontfile/fontscale.c
@@ -32,6 +32,7 @@ in this Software without prior written authorization from The Open Group.
#include <config.h>
#endif
#include "libxfontint.h"
+#include "src/util/replace.h"
#include <X11/fonts/fntfilst.h>
#include <math.h>
@@ -49,7 +50,7 @@ FontFileAddScaledInstance (FontEntryPtr entry, FontScalablePtr vals,
if (extra->numScaled == extra->sizeScaled)
{
newsize = extra->sizeScaled + 4;
- new = realloc (extra->scaled, newsize * sizeof (FontScaledRec));
+ new = reallocarray (extra->scaled, newsize, sizeof (FontScaledRec));
if (!new)
return FALSE;
extra->sizeScaled = newsize;
diff --git a/src/fontfile/renderers.c b/src/fontfile/renderers.c
index d0c4064..a457fb7 100644
--- a/src/fontfile/renderers.c
+++ b/src/fontfile/renderers.c
@@ -32,6 +32,7 @@ in this Software without prior written authorization from The Open Group.
#include <config.h>
#endif
#include "libxfontint.h"
+#include "src/util/replace.h"
#include <X11/fonts/fntfilst.h>
static FontRenderersRec renderers;
@@ -80,7 +81,7 @@ FontFilePriorityRegisterRenderer (FontRendererPtr renderer, int priority)
}
if(i >= renderers.number) {
- new = realloc (renderers.renderers, sizeof(*new) * (i + 1));
+ new = reallocarray (renderers.renderers, i + 1, sizeof(*new));
if (!new)
return FALSE;
renderers.renderers = new;
diff --git a/src/stubs/atom.c b/src/stubs/atom.c
index 82c8ca3..804a4de 100644
--- a/src/stubs/atom.c
+++ b/src/stubs/atom.c
@@ -34,6 +34,7 @@
#include <config.h>
#endif
#include "libxfontint.h"
+#include "src/util/replace.h"
#include <X11/fonts/fontmisc.h>
typedef struct _AtomList {
@@ -122,7 +123,7 @@ ResizeReverseMap(void)
newMapSize = 1000;
else
newMapSize = reverseMapSize * 2;
- newMap = realloc(reverseMap, newMapSize * sizeof(AtomListPtr));
+ newMap = reallocarray(reverseMap, newMapSize, sizeof(AtomListPtr));
if (newMap == NULL) {
fprintf(stderr, "ResizeReverseMap(): Error: Couldn't reallocate"
" reverseMap (%ld)\n",
diff --git a/src/util/fontnames.c b/src/util/fontnames.c
index b292480..4460728 100644
--- a/src/util/fontnames.c
+++ b/src/util/fontnames.c
@@ -35,6 +35,7 @@ from The Open Group.
#include <config.h>
#endif
#include "libxfontint.h"
+#include "src/util/replace.h"
#include <X11/fonts/fontmisc.h>
#include <X11/fonts/fontstruct.h>
@@ -100,8 +101,8 @@ xfont2_add_font_names_name(FontNamesPtr names,
if (size == 0)
size = 8;
- nlength = realloc(names->length, size * sizeof(int));
- nnames = realloc(names->names, size * sizeof(char *));
+ nlength = reallocarray(names->length, size, sizeof(int));
+ nnames = reallocarray(names->names, size, sizeof(char *));
if (nlength && nnames) {
names->size = size;
names->length = nlength;
diff --git a/src/util/fontutil.c b/src/util/fontutil.c
index d1b845b..f7ac507 100644
--- a/src/util/fontutil.c
+++ b/src/util/fontutil.c
@@ -34,6 +34,7 @@ from The Open Group.
#include <config.h>
#endif
#include "libxfontint.h"
+#include "src/util/replace.h"
#include <X11/fonts/fontmisc.h>
#include <X11/fonts/fontstruct.h>
#include <X11/fonts/FSproto.h>
@@ -307,8 +308,8 @@ add_range(fsRange *newrange,
}
else if (!(*nranges % range_alloc_granularity))
{
- *range = realloc(*range, (*nranges + range_alloc_granularity) *
- SIZEOF(fsRange));
+ *range = reallocarray(*range, (*nranges + range_alloc_granularity),
+ SIZEOF(fsRange));
}
/* If alloc failed, just return a null list */
diff --git a/src/util/private.c b/src/util/private.c
index 92075c2..47c2699 100644
--- a/src/util/private.c
+++ b/src/util/private.c
@@ -32,6 +32,7 @@ in this Software without prior written authorization from The Open Group.
#include <config.h>
#endif
#include "libxfontint.h"
+#include "src/util/replace.h"
#include <X11/fonts/fontmisc.h>
#include <X11/fonts/fontstruct.h>
@@ -84,7 +85,7 @@ xfont2_font_set_private(FontPtr pFont, int n, pointer ptr)
if (n > pFont->maxPrivate) {
if (pFont->devPrivates && pFont->devPrivates != (pointer)(&pFont[1])) {
- new = realloc (pFont->devPrivates, (n + 1) * sizeof (pointer));
+ new = reallocarray (pFont->devPrivates, (n + 1), sizeof (pointer));
if (!new)
return FALSE;
} else {