summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Coopersmith <alan.coopersmith@oracle.com>2015-06-04 23:30:43 -0700
committerAlan Coopersmith <alan.coopersmith@oracle.com>2018-12-08 10:06:42 -0800
commit6d1dc1f6169ebf0ba71785d461bd98129c65c862 (patch)
tree404077a4e254637baa658c474f5216a99538cdb9
parentbcf7b5aa06c23aee00af7999b58cb96a8571ac42 (diff)
Convert main src directory to use reallocarray()
-rw-r--r--src/Depths.c3
-rw-r--r--src/FSWrap.c5
-rw-r--r--src/Font.c16
-rw-r--r--src/FontInfo.c13
-rw-r--r--src/FontNames.c3
-rw-r--r--src/GetFPath.c3
-rw-r--r--src/GetMoEv.c3
-rw-r--r--src/GetPntMap.c4
-rw-r--r--src/GetRGBCMap.c3
-rw-r--r--src/LiICmaps.c4
-rw-r--r--src/LiProps.c4
-rw-r--r--src/ListExt.c3
-rw-r--r--src/ModMap.c3
-rw-r--r--src/PixFormats.c3
-rw-r--r--src/PolyReg.c5
-rw-r--r--src/PutImage.c5
-rw-r--r--src/QuColors.c5
-rw-r--r--src/QuTree.c4
-rw-r--r--src/Quarks.c13
-rw-r--r--src/RdBitF.c6
-rw-r--r--src/Region.c11
-rw-r--r--src/SetHints.c7
-rw-r--r--src/SetRGBCMap.c7
-rw-r--r--src/TextToStr.c4
-rw-r--r--src/VisUtil.c8
-rw-r--r--src/WrBitF.c3
-rw-r--r--src/XlibInt.c9
27 files changed, 89 insertions, 68 deletions
diff --git a/src/Depths.c b/src/Depths.c
index a8b719d0..dace21e5 100644
--- a/src/Depths.c
+++ b/src/Depths.c
@@ -28,6 +28,7 @@ in this Software without prior written authorization from The Open Group.
#include <config.h>
#endif
#include "Xlibint.h"
+#include "reallocarray.h"
#include <stdio.h>
/*
@@ -49,7 +50,7 @@ int *XListDepths (
register Depth *dp;
register int i;
- depths = Xmalloc (count * sizeof(int));
+ depths = Xmallocarray (count, sizeof(int));
if (!depths) return NULL;
for (i = 0, dp = scr->depths; i < count; i++, dp++)
depths[i] = dp->depth;
diff --git a/src/FSWrap.c b/src/FSWrap.c
index 92caea07..d4cdbf73 100644
--- a/src/FSWrap.c
+++ b/src/FSWrap.c
@@ -63,6 +63,7 @@ from The Open Group.
#include "Xlcint.h"
#include <ctype.h>
#include <X11/Xos.h>
+#include "reallocarray.h"
#define XMAXLIST 256
@@ -112,7 +113,7 @@ _XParseBaseFontNameList(
if (!*ptr)
break;
}
- if (!(list = Xmalloc(sizeof(char *) * (*num + 1)))) {
+ if (!(list = Xmallocarray((*num + 1), sizeof(char *)))) {
Xfree(psave);
return (char **)NULL;
}
@@ -133,7 +134,7 @@ copy_string_list(
if (string_list == NULL || list_count <= 0)
return (char **) NULL;
- string_list_ret = Xmalloc(sizeof(char *) * list_count);
+ string_list_ret = Xmallocarray(list_count, sizeof(char *));
if (string_list_ret == NULL)
return (char **) NULL;
diff --git a/src/Font.c b/src/Font.c
index a73f9b19..09d2ae91 100644
--- a/src/Font.c
+++ b/src/Font.c
@@ -31,6 +31,7 @@ authorization from the X Consortium and the XFree86 Project.
#include <config.h>
#endif
#include "Xlibint.h"
+#include "reallocarray.h"
#include <limits.h>
#if defined(XF86BIGFONT)
@@ -245,8 +246,8 @@ _XQueryFont (
/* nFontProps is a CARD16 */
nbytes = reply.nFontProps * SIZEOF(xFontProp);
if ((nbytes >> 2) <= reply_left) {
- size_t pbytes = reply.nFontProps * sizeof(XFontProp);
- fs->properties = Xmalloc (pbytes);
+ fs->properties = Xmallocarray (reply.nFontProps,
+ sizeof(XFontProp));
}
if (! fs->properties) {
Xfree(fs);
@@ -266,8 +267,8 @@ _XQueryFont (
if (reply.nCharInfos < (INT_MAX / sizeof(XCharStruct))) {
nbytes = reply.nCharInfos * SIZEOF(xCharInfo);
if ((nbytes >> 2) <= reply_left) {
- size_t cibytes = reply.nCharInfos * sizeof(XCharStruct);
- fs->per_char = Xmalloc (cibytes);
+ fs->per_char = Xmallocarray (reply.nCharInfos,
+ sizeof(XCharStruct));
}
}
if (! fs->per_char) {
@@ -489,8 +490,8 @@ _XF86BigfontQueryFont (
/* nFontProps is a CARD16 */
nbytes = reply.nFontProps * SIZEOF(xFontProp);
if ((nbytes >> 2) <= reply_left) {
- size_t pbytes = reply.nFontProps * sizeof(XFontProp);
- fs->properties = Xmalloc (pbytes);
+ fs->properties = Xmallocarray (reply.nFontProps,
+ sizeof(XFontProp));
}
if (! fs->properties) {
Xfree(fs);
@@ -529,7 +530,8 @@ _XF86BigfontQueryFont (
_XEatDataWords(dpy, reply_left);
return (XFontStruct *)NULL;
}
- if (! (fs->per_char = Xmalloc (reply.nCharInfos * sizeof(XCharStruct)))) {
+ if (! (fs->per_char = Xmallocarray (reply.nCharInfos,
+ sizeof(XCharStruct)))) {
Xfree(pUniqCI);
Xfree(fs->properties);
Xfree(fs);
diff --git a/src/FontInfo.c b/src/FontInfo.c
index a2d12c2e..f870e431 100644
--- a/src/FontInfo.c
+++ b/src/FontInfo.c
@@ -28,6 +28,7 @@ in this Software without prior written authorization from The Open Group.
#include <config.h>
#endif
#include "Xlibint.h"
+#include "reallocarray.h"
#include <limits.h>
#if defined(XF86BIGFONT)
@@ -91,22 +92,22 @@ XFontStruct **info) /* RETURN */
XFontStruct * tmp_finfo;
char ** tmp_flist;
- tmp_finfo = Xrealloc (finfo, sizeof(XFontStruct) * size);
+ tmp_finfo = Xreallocarray (finfo, size, sizeof(XFontStruct));
if (tmp_finfo)
finfo = tmp_finfo;
else
goto badmem;
- tmp_flist = Xrealloc (flist, sizeof(char *) * (size+1));
+ tmp_flist = Xreallocarray (flist, size + 1, sizeof(char *));
if (tmp_flist)
flist = tmp_flist;
else
goto badmem;
}
else {
- if (! (finfo = Xmalloc(sizeof(XFontStruct) * size)))
+ if (! (finfo = Xmallocarray(size, sizeof(XFontStruct))))
goto clearwire;
- if (! (flist = Xmalloc(sizeof(char *) * (size+1)))) {
+ if (! (flist = Xmallocarray(size + 1, sizeof(char *)))) {
Xfree(finfo);
goto clearwire;
}
@@ -137,8 +138,8 @@ XFontStruct **info) /* RETURN */
/* nFontProps is a CARD16 */
nbytes = reply.nFontProps * SIZEOF(xFontProp);
if ((nbytes >> 2) <= reply_left) {
- size_t pbytes = reply.nFontProps * sizeof(XFontProp);
- fs->properties = Xmalloc (pbytes);
+ fs->properties = Xmallocarray (reply.nFontProps,
+ sizeof(XFontProp));
}
if (! fs->properties)
goto badmem;
diff --git a/src/FontNames.c b/src/FontNames.c
index ec7d90fa..b78792d6 100644
--- a/src/FontNames.c
+++ b/src/FontNames.c
@@ -29,6 +29,7 @@ in this Software without prior written authorization from The Open Group.
#include <config.h>
#endif
#include "Xlibint.h"
+#include "reallocarray.h"
#include <limits.h>
char **
@@ -66,7 +67,7 @@ int *actualCount) /* RETURN */
}
if (rep.nFonts) {
- flist = Xmalloc (rep.nFonts * sizeof(char *));
+ flist = Xmallocarray (rep.nFonts, sizeof(char *));
if (rep.length > 0 && rep.length < (INT_MAX >> 2)) {
rlen = rep.length << 2;
ch = Xmalloc(rlen + 1);
diff --git a/src/GetFPath.c b/src/GetFPath.c
index 87d25761..7d5153b6 100644
--- a/src/GetFPath.c
+++ b/src/GetFPath.c
@@ -28,6 +28,7 @@ in this Software without prior written authorization from The Open Group.
#include <config.h>
#endif
#include "Xlibint.h"
+#include "reallocarray.h"
#include <limits.h>
char **XGetFontPath(
@@ -49,7 +50,7 @@ char **XGetFontPath(
(void) _XReply (dpy, (xReply *) &rep, 0, xFalse);
if (rep.nPaths) {
- flist = Xmalloc(rep.nPaths * sizeof (char *));
+ flist = Xmallocarray(rep.nPaths, sizeof (char *));
if (rep.length < (INT_MAX >> 2)) {
nbytes = (unsigned long) rep.length << 2;
ch = Xmalloc (nbytes + 1);
diff --git a/src/GetMoEv.c b/src/GetMoEv.c
index ad9c7727..d723f378 100644
--- a/src/GetMoEv.c
+++ b/src/GetMoEv.c
@@ -28,6 +28,7 @@ in this Software without prior written authorization from The Open Group.
#include <config.h>
#endif
#include "Xlibint.h"
+#include "reallocarray.h"
#include <limits.h>
XTimeCoord *XGetMotionEvents(
@@ -53,7 +54,7 @@ XTimeCoord *XGetMotionEvents(
}
if (rep.nEvents && (rep.nEvents < (INT_MAX / sizeof(XTimeCoord))))
- tc = Xmalloc(rep.nEvents * sizeof(XTimeCoord));
+ tc = Xmallocarray(rep.nEvents, sizeof(XTimeCoord));
if (tc == NULL) {
/* server returned either no events or a bad event count */
*nEvents = 0;
diff --git a/src/GetPntMap.c b/src/GetPntMap.c
index 07625f8a..4219a110 100644
--- a/src/GetPntMap.c
+++ b/src/GetPntMap.c
@@ -29,6 +29,7 @@ in this Software without prior written authorization from The Open Group.
#include <config.h>
#endif
#include "Xlibint.h"
+#include "reallocarray.h"
#include <limits.h>
#ifdef MIN /* some systems define this in <sys/param.h> */
@@ -112,8 +113,7 @@ XGetKeyboardMapping (Display *dpy,
nkeysyms = rep.length;
if (nkeysyms > 0) {
if (nkeysyms < (INT_MAX / sizeof (KeySym))) {
- nbytes = nkeysyms * sizeof (KeySym);
- mapping = Xmalloc (nbytes);
+ mapping = Xmallocarray (nkeysyms, sizeof (KeySym));
}
if (! mapping) {
_XEatDataWords(dpy, rep.length);
diff --git a/src/GetRGBCMap.c b/src/GetRGBCMap.c
index 5d570ad3..3d1bfa64 100644
--- a/src/GetRGBCMap.c
+++ b/src/GetRGBCMap.c
@@ -33,6 +33,7 @@ from The Open Group.
#include <X11/Xlibint.h>
#include <X11/Xutil.h>
#include "Xatomtype.h"
+#include "reallocarray.h"
#include <X11/Xatom.h>
Status XGetRGBColormaps (
@@ -99,7 +100,7 @@ Status XGetRGBColormaps (
/*
* allocate array
*/
- cmaps = Xmalloc (ncmaps * sizeof (XStandardColormap));
+ cmaps = Xmallocarray (ncmaps, sizeof (XStandardColormap));
if (!cmaps) {
Xfree (data);
return False;
diff --git a/src/LiICmaps.c b/src/LiICmaps.c
index 45a2f2fd..590b1bb0 100644
--- a/src/LiICmaps.c
+++ b/src/LiICmaps.c
@@ -28,6 +28,7 @@ in this Software without prior written authorization from The Open Group.
#include <config.h>
#endif
#include "Xlibint.h"
+#include "reallocarray.h"
Colormap *XListInstalledColormaps(
register Display *dpy,
@@ -50,8 +51,7 @@ Colormap *XListInstalledColormaps(
}
if (rep.nColormaps) {
- nbytes = rep.nColormaps * sizeof(Colormap);
- cmaps = Xmalloc(nbytes);
+ cmaps = Xmallocarray(rep.nColormaps, sizeof(Colormap));
if (! cmaps) {
_XEatDataWords(dpy, rep.length);
UnlockDisplay(dpy);
diff --git a/src/LiProps.c b/src/LiProps.c
index d9c74656..411fff62 100644
--- a/src/LiProps.c
+++ b/src/LiProps.c
@@ -28,6 +28,7 @@ in this Software without prior written authorization from The Open Group.
#include <config.h>
#endif
#include "Xlibint.h"
+#include "reallocarray.h"
Atom *XListProperties(
register Display *dpy,
@@ -49,8 +50,7 @@ Atom *XListProperties(
}
if (rep.nProperties) {
- nbytes = rep.nProperties * sizeof(Atom);
- properties = Xmalloc (nbytes);
+ properties = Xmallocarray (rep.nProperties, sizeof(Atom));
if (! properties) {
_XEatDataWords(dpy, rep.length);
UnlockDisplay(dpy);
diff --git a/src/ListExt.c b/src/ListExt.c
index a795041d..69ae53da 100644
--- a/src/ListExt.c
+++ b/src/ListExt.c
@@ -28,6 +28,7 @@ in this Software without prior written authorization from The Open Group.
#include <config.h>
#endif
#include "Xlibint.h"
+#include "reallocarray.h"
#include <limits.h>
char **XListExtensions(
@@ -54,7 +55,7 @@ char **XListExtensions(
}
if (rep.nExtensions) {
- list = Xmalloc (rep.nExtensions * sizeof (char *));
+ list = Xmallocarray (rep.nExtensions, sizeof (char *));
if (rep.length > 0 && rep.length < (INT_MAX >> 2)) {
rlen = rep.length << 2;
ch = Xmalloc (rlen + 1);
diff --git a/src/ModMap.c b/src/ModMap.c
index ca15dde2..4ceb07f3 100644
--- a/src/ModMap.c
+++ b/src/ModMap.c
@@ -28,6 +28,7 @@ in this Software without prior written authorization from The Open Group.
#include <config.h>
#endif
#include "Xlibint.h"
+#include "reallocarray.h"
#include <limits.h>
XModifierKeymap *
@@ -100,7 +101,7 @@ XNewModifiermap(int keyspermodifier)
if (res) {
res->max_keypermod = keyspermodifier;
res->modifiermap = (keyspermodifier > 0 ?
- Xmalloc(8 * keyspermodifier)
+ Xmallocarray(keyspermodifier, 8)
: (KeyCode *) NULL);
if (keyspermodifier && (res->modifiermap == NULL)) {
Xfree(res);
diff --git a/src/PixFormats.c b/src/PixFormats.c
index 6d9f64d2..f9fd3e44 100644
--- a/src/PixFormats.c
+++ b/src/PixFormats.c
@@ -28,6 +28,7 @@ in this Software without prior written authorization from The Open Group.
#include <config.h>
#endif
#include "Xlibint.h"
+#include "reallocarray.h"
#include <stdio.h>
/*
@@ -39,7 +40,7 @@ XPixmapFormatValues *XListPixmapFormats (
int *count) /* RETURN */
{
XPixmapFormatValues *formats =
- Xmalloc(dpy->nformats * sizeof (XPixmapFormatValues));
+ Xmallocarray(dpy->nformats, sizeof (XPixmapFormatValues));
if (formats) {
register int i;
diff --git a/src/PolyReg.c b/src/PolyReg.c
index 7266d3b0..0884e1ea 100644
--- a/src/PolyReg.c
+++ b/src/PolyReg.c
@@ -55,6 +55,7 @@ SOFTWARE.
#include "Xutil.h"
#include <X11/Xregion.h>
#include "poly.h"
+#include "reallocarray.h"
/*
* InsertEdgeInET
@@ -409,7 +410,7 @@ static int PtsToRegion(
numRects = ((numFullPtBlocks * NUMPTSTOBUFFER) + iCurPtBlock) >> 1;
- if (!(reg->rects = Xrealloc(reg->rects, sizeof(BOX) * numRects))) {
+ if (!(reg->rects = Xreallocarray(reg->rects, numRects, sizeof(BOX)))) {
Xfree(prevRects);
return(0);
}
@@ -519,7 +520,7 @@ XPolygonRegion(
if (Count < 2) return region;
- if (! (pETEs = Xmalloc(sizeof(EdgeTableEntry) * Count))) {
+ if (! (pETEs = Xmallocarray(Count, sizeof(EdgeTableEntry)))) {
XDestroyRegion(region);
return (Region) NULL;
}
diff --git a/src/PutImage.c b/src/PutImage.c
index 13cbba35..1954d086 100644
--- a/src/PutImage.c
+++ b/src/PutImage.c
@@ -32,6 +32,7 @@ in this Software without prior written authorization from The Open Group.
#include <stdio.h>
#include "Cr.h"
#include "ImUtil.h"
+#include "reallocarray.h"
#if defined(__STDC__) && ((defined(sun) && defined(SVR4)) || defined(WIN32))
#define RConst /**/
@@ -771,7 +772,7 @@ SendZImage(
(req_yoffset * image->bytes_per_line) +
((req_xoffset * image->bits_per_pixel) >> 3);
if ((image->bits_per_pixel == 4) && ((unsigned int) req_xoffset & 0x01)) {
- if (! (shifted_src = Xmalloc(req->height * image->bytes_per_line))) {
+ if (! (shifted_src = Xmallocarray(req->height, image->bytes_per_line))) {
UnGetReq(PutImage);
return;
}
@@ -991,7 +992,7 @@ XPutImage (
img.bits_per_pixel = dest_bits_per_pixel;
img.bytes_per_line = ROUNDUP((dest_bits_per_pixel * width),
dest_scanline_pad) >> 3;
- img.data = Xmalloc(img.bytes_per_line * height);
+ img.data = Xmallocarray(height, img.bytes_per_line);
if (img.data == NULL)
return 0;
_XInitImageFuncPtrs(&img);
diff --git a/src/QuColors.c b/src/QuColors.c
index 0b9bc508..10cf1825 100644
--- a/src/QuColors.c
+++ b/src/QuColors.c
@@ -28,6 +28,7 @@ in this Software without prior written authorization from The Open Group.
#include <config.h>
#endif
#include "Xlibint.h"
+#include "reallocarray.h"
static void
_XQueryColors(
@@ -50,9 +51,9 @@ _XQueryColors(
/* XXX this isn't very efficient */
if (_XReply(dpy, (xReply *) &rep, 0, xFalse) != 0) {
- unsigned long nbytes = (long) ncolors * SIZEOF(xrgb);
- xrgb *color = Xmalloc(nbytes);
+ xrgb *color = Xmallocarray(ncolors, sizeof(xrgb));
if (color != NULL) {
+ unsigned long nbytes = (long) ncolors * SIZEOF(xrgb);
_XRead(dpy, (char *) color, nbytes);
diff --git a/src/QuTree.c b/src/QuTree.c
index 8da2ae26..9ceef781 100644
--- a/src/QuTree.c
+++ b/src/QuTree.c
@@ -28,6 +28,7 @@ in this Software without prior written authorization from The Open Group.
#include <config.h>
#endif
#include "Xlibint.h"
+#include "reallocarray.h"
Status XQueryTree (
register Display *dpy,
@@ -51,8 +52,7 @@ Status XQueryTree (
*children = (Window *) NULL;
if (rep.nChildren != 0) {
- nbytes = rep.nChildren * sizeof(Window);
- *children = Xmalloc(nbytes);
+ *children = Xmallocarray(rep.nChildren, sizeof(Window));
if (! *children) {
_XEatDataWords(dpy, rep.length);
UnlockDisplay(dpy);
diff --git a/src/Quarks.c b/src/Quarks.c
index cfdfe07a..1068a86c 100644
--- a/src/Quarks.c
+++ b/src/Quarks.c
@@ -55,6 +55,7 @@ from The Open Group.
#include "Xlibint.h"
#include <X11/Xresource.h>
#include "Xresinternal.h"
+#include "reallocarray.h"
/* Not cost effective, at least for vanilla MIT clients */
/* #define PERMQ */
@@ -288,15 +289,15 @@ nomatch: if (!rehash)
q = nextQuark;
if (!(q & QUANTUMMASK)) {
if (!(q & CHUNKMASK)) {
- if (!(new = Xrealloc(stringTable,
- sizeof(XrmString *) *
- ((q >> QUANTUMSHIFT) + CHUNKPER))))
+ if (!(new = Xreallocarray(stringTable,
+ (q >> QUANTUMSHIFT) + CHUNKPER,
+ sizeof(XrmString *))))
goto fail;
stringTable = (XrmString **)new;
#ifdef PERMQ
- if (!(new = Xrealloc(permTable,
- sizeof(Bits *) *
- ((q >> QUANTUMSHIFT) + CHUNKPER))))
+ if (!(new = Xreallocarray(permTable,
+ (q >> QUANTUMSHIFT) + CHUNKPER,
+ sizeof(Bits *))))
goto fail;
permTable = (Bits **)new;
#endif
diff --git a/src/RdBitF.c b/src/RdBitF.c
index 8a1ad85f..62130408 100644
--- a/src/RdBitF.c
+++ b/src/RdBitF.c
@@ -49,7 +49,7 @@ from The Open Group.
#include "Xutil.h"
#include <stdio.h>
#include <ctype.h>
-
+#include "reallocarray.h"
#define MAX_SIZE 255
@@ -190,10 +190,10 @@ XReadBitmapFileData (
bytes_per_line = (ww+7)/8 + padding;
- size = bytes_per_line * hh;
- bits = Xmalloc (size);
+ bits = Xmallocarray (hh, bytes_per_line);
if (!bits)
RETURN (BitmapNoMemory);
+ size = bytes_per_line * hh;
if (version10p) {
unsigned char *ptr;
diff --git a/src/Region.c b/src/Region.c
index d5dd5561..d6d9da9d 100644
--- a/src/Region.c
+++ b/src/Region.c
@@ -77,6 +77,7 @@ SOFTWARE.
#include "Xutil.h"
#include <X11/Xregion.h>
#include "poly.h"
+#include "reallocarray.h"
#ifdef DEBUG
#include <stdio.h>
@@ -521,8 +522,8 @@ miRegionCopy(
{
BOX *prevRects = dstrgn->rects;
- dstrgn->rects = Xrealloc(dstrgn->rects,
- rgn->numRects * (sizeof(BOX)));
+ dstrgn->rects = Xreallocarray(dstrgn->rects,
+ rgn->numRects, sizeof(BOX));
if (! dstrgn->rects) {
Xfree(prevRects);
dstrgn->size = 0;
@@ -790,7 +791,7 @@ miRegionOp(
*/
newReg->size = max(reg1->numRects,reg2->numRects) * 2;
- if (! (newReg->rects = Xmalloc (sizeof(BoxRec) * newReg->size))) {
+ if (! (newReg->rects = Xmallocarray (newReg->size, sizeof(BoxRec)))) {
newReg->size = 0;
return;
}
@@ -980,8 +981,8 @@ miRegionOp(
if (REGION_NOT_EMPTY(newReg))
{
BoxPtr prev_rects = newReg->rects;
- newReg->rects = Xrealloc (newReg->rects,
- sizeof(BoxRec) * newReg->numRects);
+ newReg->rects = Xreallocarray (newReg->rects,
+ newReg->numRects, sizeof(BoxRec));
if (! newReg->rects)
newReg->rects = prev_rects;
else
diff --git a/src/SetHints.c b/src/SetHints.c
index 626a2b3a..bc46498a 100644
--- a/src/SetHints.c
+++ b/src/SetHints.c
@@ -54,6 +54,7 @@ SOFTWARE.
#include "Xatomtype.h"
#include <X11/Xatom.h>
#include <X11/Xos.h>
+#include "reallocarray.h"
#define safestrlen(s) ((s) ? strlen(s) : 0)
@@ -181,10 +182,8 @@ XSetIconSizes (
{
register int i;
xPropIconSize *pp, *prop;
-#define size_of_the_real_thing sizeof /* avoid grepping screwups */
- unsigned nbytes = count * size_of_the_real_thing(xPropIconSize);
-#undef size_of_the_real_thing
- if ((prop = pp = Xmalloc (nbytes))) {
+
+ if ((prop = pp = Xmallocarray (count, sizeof(xPropIconSize)))) {
for (i = 0; i < count; i++) {
pp->minWidth = list->min_width;
pp->minHeight = list->min_height;
diff --git a/src/SetRGBCMap.c b/src/SetRGBCMap.c
index a52de261..00b8a588 100644
--- a/src/SetRGBCMap.c
+++ b/src/SetRGBCMap.c
@@ -34,6 +34,7 @@ from The Open Group.
#include <X11/Xutil.h>
#include "Xatomtype.h"
#include <X11/Xatom.h>
+#include "reallocarray.h"
void XSetRGBColormaps (
Display *dpy,
@@ -55,9 +56,9 @@ void XSetRGBColormaps (
/*
* if doing more than one, allocate scratch space for it
*/
- if ((count > 1) && ((data = ((xPropStandardColormap *)
- Xmalloc(count*sizeof(xPropStandardColormap))))
- != NULL)) {
+ if ((count > 1) &&
+ ((data = (Xmallocarray(count,
+ sizeof(xPropStandardColormap)))) != NULL)) {
alloced_scratch_space = True;
} else {
data = &tmpdata;
diff --git a/src/TextToStr.c b/src/TextToStr.c
index de9897ae..eb1220ca 100644
--- a/src/TextToStr.c
+++ b/src/TextToStr.c
@@ -31,7 +31,7 @@ in this Software without prior written authorization from The Open Group.
#include <X11/Xlibint.h>
#include <X11/Xatom.h>
#include <X11/Xutil.h>
-
+#include "reallocarray.h"
/*
* XTextPropertyToStringList - set list and count to contain data stored in
@@ -72,7 +72,7 @@ Status XTextPropertyToStringList (
/*
* allocate list and duplicate
*/
- list = Xmalloc (nelements * sizeof (char *));
+ list = Xmallocarray (nelements, sizeof (char *));
if (!list) return False;
start = Xmalloc ((datalen + 1) * sizeof (char)); /* for <NUL> */
diff --git a/src/VisUtil.c b/src/VisUtil.c
index 17ca3631..c2ea3d10 100644
--- a/src/VisUtil.c
+++ b/src/VisUtil.c
@@ -30,6 +30,8 @@ in this Software without prior written authorization from The Open Group.
#include "Xlibint.h"
#include "Xutil.h"
#include <stdio.h>
+#include "reallocarray.h"
+
/*
* This procedure returns a list of visual information structures
* that match the specified attributes given in the visual information
@@ -75,7 +77,7 @@ XVisualInfo *XGetVisualInfo(
count = 0;
total = 10;
- if (! (vip_base = vip = Xmalloc(sizeof(XVisualInfo) * total))) {
+ if (! (vip_base = vip = Xmallocarray(total, sizeof(XVisualInfo)))) {
UnlockDisplay(dpy);
return (XVisualInfo *) NULL;
}
@@ -131,8 +133,8 @@ XVisualInfo *XGetVisualInfo(
{
XVisualInfo *old_vip_base = vip_base;
total += 10;
- if (! (vip_base = Xrealloc(vip_base,
- sizeof(XVisualInfo) * total))) {
+ if (! (vip_base = Xreallocarray(vip_base, total,
+ sizeof(XVisualInfo)))) {
Xfree(old_vip_base);
UnlockDisplay(dpy);
return (XVisualInfo *) NULL;
diff --git a/src/WrBitF.c b/src/WrBitF.c
index 75a93a79..0d4fb654 100644
--- a/src/WrBitF.c
+++ b/src/WrBitF.c
@@ -33,6 +33,7 @@ from The Open Group.
#include <X11/Xos.h>
#include "Xutil.h"
#include <stdio.h>
+#include "reallocarray.h"
#define ERR_RETURN NULL
@@ -53,7 +54,7 @@ static char *Format_Image(
bytes_per_line = (width+7)/8;
*resultsize = bytes_per_line * height; /* Calculate size of data */
- data = Xmalloc( *resultsize ); /* Get space for data */
+ data = Xmallocarray(bytes_per_line, height); /* Get space for data */
if (!data)
return(ERR_RETURN);
diff --git a/src/XlibInt.c b/src/XlibInt.c
index 903ca88f..73afe024 100644
--- a/src/XlibInt.c
+++ b/src/XlibInt.c
@@ -39,6 +39,7 @@ from The Open Group.
#endif
#include "Xlibint.h"
#include "Xprivate.h"
+#include "reallocarray.h"
#include <X11/Xpoll.h>
#include <assert.h>
#include <stdio.h>
@@ -349,7 +350,7 @@ _XRegisterInternalConnection(
new_conni = Xmalloc(sizeof(struct _XConnectionInfo));
if (!new_conni)
return 0;
- new_conni->watch_data = Xmalloc(dpy->watcher_count * sizeof(XPointer));
+ new_conni->watch_data = Xmallocarray(dpy->watcher_count, sizeof(XPointer));
if (!new_conni->watch_data) {
Xfree(new_conni);
return 0;
@@ -435,7 +436,7 @@ XInternalConnectionNumbers(
count = 0;
for (info_list=dpy->im_fd_info; info_list; info_list=info_list->next)
count++;
- fd_list = Xmalloc (count * sizeof(int));
+ fd_list = Xmallocarray (count, sizeof(int));
if (!fd_list) {
UnlockDisplay(dpy);
return 0;
@@ -508,8 +509,8 @@ XAddConnectionWatch(
/* allocate new watch data */
for (info_list=dpy->im_fd_info; info_list; info_list=info_list->next) {
- wd_array = Xrealloc(info_list->watch_data,
- (dpy->watcher_count + 1) * sizeof(XPointer));
+ wd_array = Xreallocarray(info_list->watch_data,
+ dpy->watcher_count + 1, sizeof(XPointer));
if (!wd_array) {
UnlockDisplay(dpy);
return 0;