From f54470dab5b392380df61a22b4b4bef685b6cee2 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Sat, 3 Aug 2019 19:09:19 -0700 Subject: Convert multiplying realloc calls to use reallocarray instead Signed-off-by: Alan Coopersmith --- Makefile.am | 2 +- src/FreeType/ftfuncs.c | 2 +- src/fontfile/bitsource.c | 3 ++- src/fontfile/catalogue.c | 4 +++- src/fontfile/fontdir.c | 2 +- src/fontfile/fontscale.c | 3 ++- src/fontfile/renderers.c | 3 ++- src/stubs/atom.c | 3 ++- src/util/fontnames.c | 5 +++-- src/util/fontutil.c | 5 +++-- src/util/private.c | 3 ++- test/utils/font-test-utils.c | 4 +++- 12 files changed, 25 insertions(+), 14 deletions(-) diff --git a/Makefile.am b/Makefile.am index 393d09e..0500b93 100644 --- a/Makefile.am +++ b/Makefile.am @@ -165,7 +165,7 @@ TEST_UTIL_SRCS = test/utils/font-test-utils.c test/utils/font-test-utils.h noinst_PROGRAMS = lsfontdir lsfontdir_SOURCES = test/utils/lsfontdir.c $(TEST_UTIL_SRCS) -lsfontdir_LDADD = libXfont2.la +lsfontdir_LDADD = libXfont2.la $(LTLIBOBJS) MAINTAINERCLEANFILES = ChangeLog INSTALL 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 #endif #include "libxfontint.h" +#include "src/util/replace.h" #include 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 #include #include +#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 #endif #include "libxfontint.h" +#include "src/util/replace.h" #include #include @@ -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 #endif #include "libxfontint.h" +#include "src/util/replace.h" #include 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 #endif #include "libxfontint.h" +#include "src/util/replace.h" #include 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 #endif #include "libxfontint.h" +#include "src/util/replace.h" #include #include @@ -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 #endif #include "libxfontint.h" +#include "src/util/replace.h" #include #include #include @@ -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 #endif #include "libxfontint.h" +#include "src/util/replace.h" #include #include @@ -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 { diff --git a/test/utils/font-test-utils.c b/test/utils/font-test-utils.c index bc4039e..ff05061 100644 --- a/test/utils/font-test-utils.c +++ b/test/utils/font-test-utils.c @@ -53,6 +53,7 @@ SOFTWARE. */ #include "font-test-utils.h" +#include "src/util/replace.h" #include #include #include @@ -133,7 +134,8 @@ test_register_fpe_funcs(const xfont2_fpe_funcs_rec *funcs) xfont2_fpe_funcs_rec const **new; /* grow the list */ - new = realloc(fpe_functions, (num_fpe_types + 1) * sizeof(xfont2_fpe_funcs_ptr)); + new = reallocarray(fpe_functions, (num_fpe_types + 1), + sizeof(xfont2_fpe_funcs_ptr)); assert (new != NULL); fpe_functions = new; -- cgit v1.2.1