summaryrefslogtreecommitdiff
path: root/src/bitmap/pcfread.c
diff options
context:
space:
mode:
authorAlan Coopersmith <alan.coopersmith@oracle.com>2019-08-03 19:29:05 -0700
committerAlan Coopersmith <alan.coopersmith@oracle.com>2019-08-04 11:23:20 -0700
commitddbee30d3525cdd66b84056affc407601680cc29 (patch)
treeae251a90a3e4cd3420d361edba93a4ea3656babc /src/bitmap/pcfread.c
parentf54470dab5b392380df61a22b4b4bef685b6cee2 (diff)
Convert multiplying malloc calls to use mallocarray instead
Introduces mallocarray as a macro calling reallocarray with a NULL pointer for the old allocation. Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Diffstat (limited to 'src/bitmap/pcfread.c')
-rw-r--r--src/bitmap/pcfread.c13
1 files changed, 7 insertions, 6 deletions
diff --git a/src/bitmap/pcfread.c b/src/bitmap/pcfread.c
index ae34c28..bf64d6f 100644
--- a/src/bitmap/pcfread.c
+++ b/src/bitmap/pcfread.c
@@ -34,6 +34,7 @@ from The Open Group.
#include <config.h>
#endif
#include "libxfontint.h"
+#include "src/util/replace.h"
#include <X11/fonts/fntfilst.h>
#include <X11/fonts/bitmap.h>
@@ -138,7 +139,7 @@ pcfReadTOC(FontFilePtr file, int *countp)
pcfError("pcfReadTOC(): invalid file format\n");
return NULL;
}
- tables = malloc(count * sizeof(PCFTableRec));
+ tables = mallocarray(count, sizeof(PCFTableRec));
if (!tables) {
pcfError("pcfReadTOC(): Couldn't allocate tables (%d*%d)\n",
count, (int) sizeof(PCFTableRec));
@@ -263,13 +264,13 @@ pcfGetProperties(FontInfoPtr pFontInfo, FontFilePtr file,
goto Bail;
}
if (IS_EOF(file)) goto Bail;
- props = malloc(nprops * sizeof(FontPropRec));
+ props = mallocarray(nprops, sizeof(FontPropRec));
if (!props) {
pcfError("pcfGetProperties(): Couldn't allocate props (%d*%d)\n",
nprops, (int) sizeof(FontPropRec));
goto Bail;
}
- isStringProp = malloc(nprops * sizeof(char));
+ isStringProp = mallocarray(nprops, sizeof(char));
if (!isStringProp) {
pcfError("pcfGetProperties(): Couldn't allocate isStringProp (%d*%d)\n",
nprops, (int) sizeof(char));
@@ -456,7 +457,7 @@ pcfReadFont(FontPtr pFont, FontFilePtr file,
pcfError("pcfReadFont(): invalid file format\n");
goto Bail;
}
- metrics = malloc(nmetrics * sizeof(CharInfoRec));
+ metrics = mallocarray(nmetrics, sizeof(CharInfoRec));
if (!metrics) {
pcfError("pcfReadFont(): Couldn't allocate metrics (%d*%d)\n",
nmetrics, (int) sizeof(CharInfoRec));
@@ -483,7 +484,7 @@ pcfReadFont(FontPtr pFont, FontFilePtr file,
if (nbitmaps != nmetrics || IS_EOF(file))
goto Bail;
/* nmetrics is already ok, so nbitmap also is */
- offsets = malloc(nbitmaps * sizeof(CARD32));
+ offsets = mallocarray(nbitmaps, sizeof(CARD32));
if (!offsets) {
pcfError("pcfReadFont(): Couldn't allocate offsets (%d*%d)\n",
nbitmaps, (int) sizeof(CARD32));
@@ -573,7 +574,7 @@ pcfReadFont(FontPtr pFont, FontFilePtr file,
if (nink_metrics != nmetrics)
goto Bail;
/* nmetrics already checked */
- ink_metrics = malloc(nink_metrics * sizeof(xCharInfo));
+ ink_metrics = mallocarray(nink_metrics, sizeof(xCharInfo));
if (!ink_metrics) {
pcfError("pcfReadFont(): Couldn't allocate ink_metrics (%d*%d)\n",
nink_metrics, (int) sizeof(xCharInfo));