[PATCH 09/17] Convert top level extensions to new *allocarray functions
Alan Coopersmith
alan.coopersmith at oracle.com
Tue Mar 31 17:50:22 PDT 2015
Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
---
Xext/hashtable.c | 4 ++--
Xext/panoramiX.c | 10 +++++-----
Xext/panoramiXprocs.c | 19 +++++++++----------
Xext/saver.c | 2 +-
Xext/shape.c | 2 +-
Xext/sync.c | 4 ++--
Xext/xcmisc.c | 2 +-
Xext/xf86bigfont.c | 4 ++--
Xext/xres.c | 2 +-
Xext/xselinux_label.c | 2 +-
Xext/xvmain.c | 2 +-
Xi/exevents.c | 6 +++---
Xi/getprop.c | 2 +-
Xi/xiproperty.c | 8 +++-----
composite/compinit.c | 8 ++++----
dbe/dbe.c | 14 ++++++--------
dbe/midbe.c | 2 +-
pseudoramiX/pseudoramiX.c | 6 +++---
randr/rrcrtc.c | 14 +++++++-------
randr/rrinfo.c | 10 +++++-----
randr/rrmode.c | 4 ++--
randr/rroutput.c | 14 +++++++-------
randr/rrproperty.c | 12 +++++-------
randr/rrproviderproperty.c | 6 +++---
randr/rrtransform.c | 2 +-
record/record.c | 35 ++++++++++++++++-------------------
record/set.c | 4 +---
render/filter.c | 12 ++++++------
render/miindex.c | 2 +-
render/mipict.c | 4 ++--
render/picture.c | 2 +-
render/render.c | 6 +++---
xfixes/region.c | 2 +-
33 files changed, 108 insertions(+), 120 deletions(-)
diff --git a/Xext/hashtable.c b/Xext/hashtable.c
index 471ecca..41b2e00 100644
--- a/Xext/hashtable.c
+++ b/Xext/hashtable.c
@@ -54,7 +54,7 @@ ht_create(int keySize,
ht->elements = 0;
ht->bucketBits = INITHASHSIZE;
numBuckets = 1 << ht->bucketBits;
- ht->buckets = malloc(numBuckets * sizeof(*ht->buckets));
+ ht->buckets = xallocarray(numBuckets, sizeof(*ht->buckets));
ht->cdata = cdata;
if (ht->buckets) {
@@ -92,7 +92,7 @@ double_size(HashTable ht)
int newNumBuckets = 1 << newBucketBits;
int c;
- newBuckets = malloc(newNumBuckets * sizeof(*ht->buckets));
+ newBuckets = xallocarray(newNumBuckets, sizeof(*ht->buckets));
if (newBuckets) {
for (c = 0; c < newNumBuckets; ++c) {
xorg_list_init(&newBuckets[c]);
diff --git a/Xext/panoramiX.c b/Xext/panoramiX.c
index 2bbae2f..209df29 100644
--- a/Xext/panoramiX.c
+++ b/Xext/panoramiX.c
@@ -747,13 +747,13 @@ PanoramiXMaybeAddDepth(DepthPtr pDepth)
j = PanoramiXNumDepths;
PanoramiXNumDepths++;
- PanoramiXDepths = realloc(PanoramiXDepths,
- PanoramiXNumDepths * sizeof(DepthRec));
+ PanoramiXDepths = reallocarray(PanoramiXDepths,
+ PanoramiXNumDepths, sizeof(DepthRec));
PanoramiXDepths[j].depth = pDepth->depth;
PanoramiXDepths[j].numVids = 0;
/* XXX suboptimal, should grow these dynamically */
if (pDepth->numVids)
- PanoramiXDepths[j].vids = malloc(sizeof(VisualID) * pDepth->numVids);
+ PanoramiXDepths[j].vids = xallocarray(pDepth->numVids, sizeof(VisualID));
else
PanoramiXDepths[j].vids = NULL;
}
@@ -789,8 +789,8 @@ PanoramiXMaybeAddVisual(VisualPtr pVisual)
/* found a matching visual on all screens, add it to the subset list */
j = PanoramiXNumVisuals;
PanoramiXNumVisuals++;
- PanoramiXVisuals = realloc(PanoramiXVisuals,
- PanoramiXNumVisuals * sizeof(VisualRec));
+ PanoramiXVisuals = reallocarray(PanoramiXVisuals,
+ PanoramiXNumVisuals, sizeof(VisualRec));
memcpy(&PanoramiXVisuals[j], pVisual, sizeof(VisualRec));
diff --git a/Xext/panoramiXprocs.c b/Xext/panoramiXprocs.c
index 5291a4a..9eb29bd 100644
--- a/Xext/panoramiXprocs.c
+++ b/Xext/panoramiXprocs.c
@@ -1341,7 +1341,7 @@ PanoramiXPolyPoint(ClientPtr client)
isRoot = (draw->type == XRT_WINDOW) && draw->u.win.root;
npoint = bytes_to_int32((client->req_len << 2) - sizeof(xPolyPointReq));
if (npoint > 0) {
- origPts = malloc(npoint * sizeof(xPoint));
+ origPts = xallocarray(npoint, sizeof(xPoint));
memcpy((char *) origPts, (char *) &stuff[1], npoint * sizeof(xPoint));
FOR_NSCREENS_FORWARD(j) {
@@ -1406,7 +1406,7 @@ PanoramiXPolyLine(ClientPtr client)
isRoot = IS_ROOT_DRAWABLE(draw);
npoint = bytes_to_int32((client->req_len << 2) - sizeof(xPolyLineReq));
if (npoint > 0) {
- origPts = malloc(npoint * sizeof(xPoint));
+ origPts = xallocarray(npoint, sizeof(xPoint));
memcpy((char *) origPts, (char *) &stuff[1], npoint * sizeof(xPoint));
FOR_NSCREENS_FORWARD(j) {
@@ -1475,7 +1475,7 @@ PanoramiXPolySegment(ClientPtr client)
return BadLength;
nsegs >>= 3;
if (nsegs > 0) {
- origSegs = malloc(nsegs * sizeof(xSegment));
+ origSegs = xallocarray(nsegs, sizeof(xSegment));
memcpy((char *) origSegs, (char *) &stuff[1], nsegs * sizeof(xSegment));
FOR_NSCREENS_FORWARD(j) {
@@ -1543,7 +1543,7 @@ PanoramiXPolyRectangle(ClientPtr client)
return BadLength;
nrects >>= 3;
if (nrects > 0) {
- origRecs = malloc(nrects * sizeof(xRectangle));
+ origRecs = xallocarray(nrects, sizeof(xRectangle));
memcpy((char *) origRecs, (char *) &stuff[1],
nrects * sizeof(xRectangle));
FOR_NSCREENS_FORWARD(j) {
@@ -1610,7 +1610,7 @@ PanoramiXPolyArc(ClientPtr client)
return BadLength;
narcs /= sizeof(xArc);
if (narcs > 0) {
- origArcs = malloc(narcs * sizeof(xArc));
+ origArcs = xallocarray(narcs, sizeof(xArc));
memcpy((char *) origArcs, (char *) &stuff[1], narcs * sizeof(xArc));
FOR_NSCREENS_FORWARD(j) {
@@ -1672,7 +1672,7 @@ PanoramiXFillPoly(ClientPtr client)
count = bytes_to_int32((client->req_len << 2) - sizeof(xFillPolyReq));
if (count > 0) {
- locPts = malloc(count * sizeof(DDXPointRec));
+ locPts = xallocarray(count, sizeof(DDXPointRec));
memcpy((char *) locPts, (char *) &stuff[1],
count * sizeof(DDXPointRec));
FOR_NSCREENS_FORWARD(j) {
@@ -1741,7 +1741,7 @@ PanoramiXPolyFillRectangle(ClientPtr client)
return BadLength;
things >>= 3;
if (things > 0) {
- origRects = malloc(things * sizeof(xRectangle));
+ origRects = xallocarray(things, sizeof(xRectangle));
memcpy((char *) origRects, (char *) &stuff[1],
things * sizeof(xRectangle));
FOR_NSCREENS_FORWARD(j) {
@@ -1808,7 +1808,7 @@ PanoramiXPolyFillArc(ClientPtr client)
return BadLength;
narcs /= sizeof(xArc);
if (narcs > 0) {
- origArcs = malloc(narcs * sizeof(xArc));
+ origArcs = xallocarray(narcs, sizeof(xArc));
memcpy((char *) origArcs, (char *) &stuff[1], narcs * sizeof(xArc));
FOR_NSCREENS_FORWARD(j) {
@@ -1988,8 +1988,7 @@ PanoramiXGetImage(ClientPtr client)
if (linesPerBuf > h)
linesPerBuf = h;
}
- length = linesPerBuf * widthBytesLine;
- if (!(pBuf = malloc(length)))
+ if (!(pBuf = xallocarray(linesPerBuf, widthBytesLine)))
return BadAlloc;
WriteReplyToClient(client, sizeof(xGetImageReply), &xgi);
diff --git a/Xext/saver.c b/Xext/saver.c
index 2c14ea0..0e20467 100644
--- a/Xext/saver.c
+++ b/Xext/saver.c
@@ -853,7 +853,7 @@ ScreenSaverSetAttributes(ClientPtr client)
goto bail;
}
/* over allocate for override redirect */
- pAttr->values = values = malloc((len + 1) * sizeof(unsigned long));
+ pAttr->values = values = xallocarray(len + 1, sizeof(unsigned long));
if (!values) {
ret = BadAlloc;
goto bail;
diff --git a/Xext/shape.c b/Xext/shape.c
index bb479b1..2fc789e 100644
--- a/Xext/shape.c
+++ b/Xext/shape.c
@@ -996,7 +996,7 @@ ProcShapeGetRectangles(ClientPtr client)
nrects = RegionNumRects(region);
box = RegionRects(region);
- rects = malloc(nrects * sizeof(xRectangle));
+ rects = xallocarray(nrects, sizeof(xRectangle));
if (!rects && nrects)
return BadAlloc;
for (i = 0; i < nrects; i++, box++) {
diff --git a/Xext/sync.c b/Xext/sync.c
index ba08cd1..4140561 100644
--- a/Xext/sync.c
+++ b/Xext/sync.c
@@ -620,7 +620,7 @@ SyncAwaitTriggerFired(SyncTrigger * pTrigger)
pAwaitUnion = (SyncAwaitUnion *) pAwait->pHeader;
numwaits = pAwaitUnion->header.num_waitconditions;
- ppAwait = malloc(numwaits * sizeof(SyncAwait *));
+ ppAwait = xallocarray(numwaits, sizeof(SyncAwait *));
if (!ppAwait)
goto bail;
@@ -1514,7 +1514,7 @@ SyncAwaitPrologue(ClientPtr client, int items)
/* all the memory for the entire await list is allocated
* here in one chunk
*/
- pAwaitUnion = malloc((items + 1) * sizeof(SyncAwaitUnion));
+ pAwaitUnion = xallocarray(items + 1, sizeof(SyncAwaitUnion));
if (!pAwaitUnion)
return NULL;
diff --git a/Xext/xcmisc.c b/Xext/xcmisc.c
index 1e91010..ed25650 100644
--- a/Xext/xcmisc.c
+++ b/Xext/xcmisc.c
@@ -101,7 +101,7 @@ ProcXCMiscGetXIDList(ClientPtr client)
if (stuff->count > UINT32_MAX / sizeof(XID))
return BadAlloc;
- pids = (XID *) malloc(stuff->count * sizeof(XID));
+ pids = xallocarray(stuff->count, sizeof(XID));
if (!pids) {
return BadAlloc;
}
diff --git a/Xext/xf86bigfont.c b/Xext/xf86bigfont.c
index 46b3242..95b5371 100644
--- a/Xext/xf86bigfont.c
+++ b/Xext/xf86bigfont.c
@@ -401,7 +401,7 @@ ProcXF86BigfontQueryFont(ClientPtr client)
}
else {
#endif
- pCI = malloc(nCharInfos * sizeof(xCharInfo));
+ pCI = xallocarray(nCharInfos, sizeof(xCharInfo));
if (!pCI)
return BadAlloc;
#ifdef HAS_SHM
@@ -463,7 +463,7 @@ ProcXF86BigfontQueryFont(ClientPtr client)
if (hashModulus > nCharInfos + 1)
hashModulus = nCharInfos + 1;
- tmp = malloc((4 * nCharInfos + 1) * sizeof(CARD16));
+ tmp = xallocarray(4 * nCharInfos + 1, sizeof(CARD16));
if (!tmp) {
if (!pDesc)
free(pCI);
diff --git a/Xext/xres.c b/Xext/xres.c
index 2737938..6b87c3d 100644
--- a/Xext/xres.c
+++ b/Xext/xres.c
@@ -223,7 +223,7 @@ ProcXResQueryClients(ClientPtr client)
REQUEST_SIZE_MATCH(xXResQueryClientsReq);
- current_clients = malloc(currentMaxClients * sizeof(int));
+ current_clients = xallocarray(currentMaxClients, sizeof(int));
num_clients = 0;
for (i = 0; i < currentMaxClients; i++) {
diff --git a/Xext/xselinux_label.c b/Xext/xselinux_label.c
index 2c33d1c..8559385 100644
--- a/Xext/xselinux_label.c
+++ b/Xext/xselinux_label.c
@@ -64,7 +64,7 @@ SELinuxArraySet(SELinuxArrayRec * rec, unsigned key, void *val)
{
if (key >= rec->size) {
/* Need to increase size of array */
- rec->array = realloc(rec->array, (key + 1) * sizeof(val));
+ rec->array = reallocarray(rec->array, key + 1, sizeof(val));
if (!rec->array)
return FALSE;
memset(rec->array + rec->size, 0, (key - rec->size + 1) * sizeof(val));
diff --git a/Xext/xvmain.c b/Xext/xvmain.c
index 0abf190..93e5f0c 100644
--- a/Xext/xvmain.c
+++ b/Xext/xvmain.c
@@ -1102,7 +1102,7 @@ XvFillColorKey(DrawablePtr pDraw, CARD32 key, RegionPtr region)
(void) ChangeGC(NullClient, gc, GCForeground | GCSubwindowMode, pval);
ValidateGC(pDraw, gc);
- rects = malloc(nbox * sizeof(xRectangle));
+ rects = xallocarray(nbox, sizeof(xRectangle));
if (rects) {
for (i = 0; i < nbox; i++, pbox++) {
rects[i].x = pbox->x1 - pDraw->x;
diff --git a/Xi/exevents.c b/Xi/exevents.c
index 0857bce..1c586d0 100644
--- a/Xi/exevents.c
+++ b/Xi/exevents.c
@@ -471,9 +471,9 @@ DeepCopyKeyboardClasses(DeviceIntPtr from, DeviceIntPtr to)
oldTrace = to->focus->trace;
memcpy(to->focus, from->focus, sizeof(FocusClassRec));
- to->focus->trace = realloc(oldTrace,
- to->focus->traceSize *
- sizeof(WindowPtr));
+ to->focus->trace = reallocarray(oldTrace,
+ to->focus->traceSize,
+ sizeof(WindowPtr));
if (!to->focus->trace && to->focus->traceSize)
FatalError("[Xi] no memory for trace.\n");
memcpy(to->focus->trace, from->focus->trace,
diff --git a/Xi/getprop.c b/Xi/getprop.c
index 4d6ce63..19f18af 100644
--- a/Xi/getprop.c
+++ b/Xi/getprop.c
@@ -118,7 +118,7 @@ ProcXGetDeviceDontPropagateList(ClientPtr client)
ClassFromMask(NULL, others->dontPropagateMask[i], i, &count, COUNT);
if (count) {
rep.count = count;
- buf = (XEventClass *) malloc(rep.count * sizeof(XEventClass));
+ buf = xallocarray(rep.count, sizeof(XEventClass));
rep.length = bytes_to_int32(rep.count * sizeof(XEventClass));
tbuf = buf;
diff --git a/Xi/xiproperty.c b/Xi/xiproperty.c
index 8e8e4b0..e3b8f5a 100644
--- a/Xi/xiproperty.c
+++ b/Xi/xiproperty.c
@@ -221,7 +221,7 @@ list_atoms(DeviceIntPtr dev, int *natoms, Atom **atoms_return)
if (nprops) {
Atom *a;
- atoms = malloc(nprops * sizeof(Atom));
+ atoms = xallocarray(nprops, sizeof(Atom));
if (!atoms)
return BadAlloc;
a = atoms;
@@ -687,7 +687,6 @@ XIChangeDeviceProperty(DeviceIntPtr dev, Atom property, Atom type,
{
XIPropertyPtr prop;
int size_in_bytes;
- int total_size;
unsigned long total_len;
XIPropertyValuePtr prop_value;
XIPropertyValueRec new_value;
@@ -725,9 +724,8 @@ XIChangeDeviceProperty(DeviceIntPtr dev, Atom property, Atom type,
if (mode == PropModeReplace || len > 0) {
void *new_data = NULL, *old_data = NULL;
- total_size = total_len * size_in_bytes;
- new_value.data = (void *) malloc(total_size);
- if (!new_value.data && total_size) {
+ new_value.data = xallocarray(total_len, size_in_bytes);
+ if (!new_value.data && total_len && size_in_bytes) {
if (add)
XIDestroyDeviceProperty(prop);
return BadAlloc;
diff --git a/composite/compinit.c b/composite/compinit.c
index 3ac075a..28ceacd 100644
--- a/composite/compinit.c
+++ b/composite/compinit.c
@@ -223,8 +223,8 @@ compRegisterAlternateVisuals(CompScreenPtr cs, VisualID * vids, int nVisuals)
{
VisualID *p;
- p = realloc(cs->alternateVisuals,
- sizeof(VisualID) * (cs->numAlternateVisuals + nVisuals));
+ p = reallocarray(cs->alternateVisuals,
+ (cs->numAlternateVisuals + nVisuals), sizeof(VisualID));
if (p == NULL)
return FALSE;
@@ -253,8 +253,8 @@ CompositeRegisterImplicitRedirectionException(ScreenPtr pScreen,
CompScreenPtr cs = GetCompScreen(pScreen);
CompImplicitRedirectException *p;
- p = realloc(cs->implicitRedirectExceptions,
- sizeof(p[0]) * (cs->numImplicitRedirectExceptions + 1));
+ p = reallocarray(cs->implicitRedirectExceptions,
+ (cs->numImplicitRedirectExceptions + 1), sizeof(p[0]));
if (p == NULL)
return FALSE;
diff --git a/dbe/dbe.c b/dbe/dbe.c
index e5d928d..23f7e16 100644
--- a/dbe/dbe.c
+++ b/dbe/dbe.c
@@ -287,11 +287,10 @@ ProcDbeAllocateBackBufferName(ClientPtr client)
}
/* malloc/realloc a new array and initialize all elements to 0. */
- pDbeWindowPriv->IDs = (XID *) realloc(pIDs,
- (pDbeWindowPriv->
- maxAvailableIDs +
- DBE_INCR_MAX_IDS) *
- sizeof(XID));
+ pDbeWindowPriv->IDs =
+ reallocarray(pIDs,
+ pDbeWindowPriv->maxAvailableIDs + DBE_INCR_MAX_IDS,
+ sizeof(XID));
if (!pDbeWindowPriv->IDs) {
return BadAlloc;
}
@@ -470,7 +469,7 @@ ProcDbeSwapBuffers(ClientPtr client)
dbeSwapInfo = (xDbeSwapInfo *) &stuff[1];
/* Allocate array to record swap information. */
- swapInfo = (DbeSwapInfoPtr) malloc(nStuff * sizeof(DbeSwapInfoRec));
+ swapInfo = xallocarray(nStuff, sizeof(DbeSwapInfoRec));
if (swapInfo == NULL) {
return BadAlloc;
}
@@ -580,8 +579,7 @@ ProcDbeGetVisualInfo(ClientPtr client)
return BadAlloc;
/* Make sure any specified drawables are valid. */
if (stuff->n != 0) {
- if (!(pDrawables = (DrawablePtr *) malloc(stuff->n *
- sizeof(DrawablePtr)))) {
+ if (!(pDrawables = xallocarray(stuff->n, sizeof(DrawablePtr)))) {
return BadAlloc;
}
diff --git a/dbe/midbe.c b/dbe/midbe.c
index 8f75910..9684d45 100644
--- a/dbe/midbe.c
+++ b/dbe/midbe.c
@@ -87,7 +87,7 @@ miDbeGetVisualInfo(ScreenPtr pScreen, XdbeScreenVisualInfo * pScrVisInfo)
}
/* Allocate an array of XdbeVisualInfo items. */
- if (!(visInfo = (XdbeVisualInfo *) malloc(count * sizeof(XdbeVisualInfo)))) {
+ if (!(visInfo = xallocarray(count, sizeof(XdbeVisualInfo)))) {
return FALSE; /* memory alloc failure */
}
diff --git a/pseudoramiX/pseudoramiX.c b/pseudoramiX/pseudoramiX.c
index e59ca13..d8b2593 100644
--- a/pseudoramiX/pseudoramiX.c
+++ b/pseudoramiX/pseudoramiX.c
@@ -140,9 +140,9 @@ PseudoramiXAddScreen(int x, int y, int w, int h)
if (pseudoramiXNumScreens == pseudoramiXScreensAllocated) {
pseudoramiXScreensAllocated += pseudoramiXScreensAllocated + 1;
- pseudoramiXScreens = realloc(pseudoramiXScreens,
- pseudoramiXScreensAllocated *
- sizeof(PseudoramiXScreenRec));
+ pseudoramiXScreens = reallocarray(pseudoramiXScreens,
+ pseudoramiXScreensAllocated,
+ sizeof(PseudoramiXScreenRec));
}
DEBUG_LOG("x: %d, y: %d, w: %d, h: %d\n", x, y, w, h);
diff --git a/randr/rrcrtc.c b/randr/rrcrtc.c
index 69b3ecf..210f609 100644
--- a/randr/rrcrtc.c
+++ b/randr/rrcrtc.c
@@ -65,8 +65,8 @@ RRCrtcCreate(ScreenPtr pScreen, void *devPrivate)
/* make space for the crtc pointer */
if (pScrPriv->numCrtcs)
- crtcs = realloc(pScrPriv->crtcs,
- (pScrPriv->numCrtcs + 1) * sizeof(RRCrtcPtr));
+ crtcs = reallocarray(pScrPriv->crtcs,
+ (pScrPriv->numCrtcs + 1), sizeof(RRCrtcPtr));
else
crtcs = malloc(sizeof(RRCrtcPtr));
if (!crtcs)
@@ -176,10 +176,10 @@ RRCrtcNotify(RRCrtcPtr crtc,
if (numOutputs) {
if (crtc->numOutputs)
- newoutputs = realloc(crtc->outputs,
- numOutputs * sizeof(RROutputPtr));
+ newoutputs = reallocarray(crtc->outputs,
+ numOutputs, sizeof(RROutputPtr));
else
- newoutputs = malloc(numOutputs * sizeof(RROutputPtr));
+ newoutputs = xallocarray(numOutputs, sizeof(RROutputPtr));
if (!newoutputs)
return FALSE;
}
@@ -798,7 +798,7 @@ RRCrtcGammaSetSize(RRCrtcPtr crtc, int size)
if (size == crtc->gammaSize)
return TRUE;
if (size) {
- gamma = malloc(size * 3 * sizeof(CARD16));
+ gamma = xallocarray(size, 3 * sizeof(CARD16));
if (!gamma)
return FALSE;
}
@@ -1027,7 +1027,7 @@ ProcRRSetCrtcConfig(ClientPtr client)
return BadMatch;
}
if (numOutputs) {
- outputs = malloc(numOutputs * sizeof(RROutputPtr));
+ outputs = xallocarray(numOutputs, sizeof(RROutputPtr));
if (!outputs)
return BadAlloc;
}
diff --git a/randr/rrinfo.c b/randr/rrinfo.c
index fc57bd4..24245b7 100644
--- a/randr/rrinfo.c
+++ b/randr/rrinfo.c
@@ -55,8 +55,8 @@ RROldModeAdd(RROutputPtr output, RRScreenSizePtr size, int refresh)
}
if (output->numModes)
- modes = realloc(output->modes,
- (output->numModes + 1) * sizeof(RRModePtr));
+ modes = reallocarray(output->modes,
+ output->numModes + 1, sizeof(RRModePtr));
else
modes = malloc(sizeof(RRModePtr));
if (!modes) {
@@ -266,8 +266,8 @@ RRRegisterSize(ScreenPtr pScreen,
for (i = 0; i < pScrPriv->nSizes; i++)
if (RRScreenSizeMatches(&tmp, &pScrPriv->pSizes[i]))
return &pScrPriv->pSizes[i];
- pNew = realloc(pScrPriv->pSizes,
- (pScrPriv->nSizes + 1) * sizeof(RRScreenSize));
+ pNew = reallocarray(pScrPriv->pSizes,
+ pScrPriv->nSizes + 1, sizeof(RRScreenSize));
if (!pNew)
return 0;
pNew[pScrPriv->nSizes++] = tmp;
@@ -289,7 +289,7 @@ RRRegisterRate(ScreenPtr pScreen, RRScreenSizePtr pSize, int rate)
if (pSize->pRates[i].rate == rate)
return TRUE;
- pNew = realloc(pSize->pRates, (pSize->nRates + 1) * sizeof(RRScreenRate));
+ pNew = reallocarray(pSize->pRates, pSize->nRates + 1, sizeof(RRScreenRate));
if (!pNew)
return FALSE;
pRate = &pNew[pSize->nRates++];
diff --git a/randr/rrmode.c b/randr/rrmode.c
index befac47..a7aa433 100644
--- a/randr/rrmode.c
+++ b/randr/rrmode.c
@@ -79,7 +79,7 @@ RRModeCreate(xRRModeInfo * modeInfo, const char *name, ScreenPtr userScreen)
mode->userScreen = userScreen;
if (num_modes)
- newModes = realloc(modes, (num_modes + 1) * sizeof(RRModePtr));
+ newModes = reallocarray(modes, num_modes + 1, sizeof(RRModePtr));
else
newModes = malloc(sizeof(RRModePtr));
@@ -166,7 +166,7 @@ RRModesForScreen(ScreenPtr pScreen, int *num_ret)
RRModePtr *screen_modes;
int num_screen_modes = 0;
- screen_modes = malloc((num_modes ? num_modes : 1) * sizeof(RRModePtr));
+ screen_modes = xallocarray((num_modes ? num_modes : 1), sizeof(RRModePtr));
if (!screen_modes)
return NULL;
diff --git a/randr/rroutput.c b/randr/rroutput.c
index 548e07d..10df4da 100644
--- a/randr/rroutput.c
+++ b/randr/rroutput.c
@@ -60,8 +60,8 @@ RROutputCreate(ScreenPtr pScreen,
pScrPriv = rrGetScrPriv(pScreen);
if (pScrPriv->numOutputs)
- outputs = realloc(pScrPriv->outputs,
- (pScrPriv->numOutputs + 1) * sizeof(RROutputPtr));
+ outputs = reallocarray(pScrPriv->outputs,
+ pScrPriv->numOutputs + 1, sizeof(RROutputPtr));
else
outputs = malloc(sizeof(RROutputPtr));
if (!outputs)
@@ -124,7 +124,7 @@ RROutputSetClones(RROutputPtr output, RROutputPtr * clones, int numClones)
return TRUE;
}
if (numClones) {
- newClones = malloc(numClones * sizeof(RROutputPtr));
+ newClones = xallocarray(numClones, sizeof(RROutputPtr));
if (!newClones)
return FALSE;
}
@@ -157,7 +157,7 @@ RROutputSetModes(RROutputPtr output,
}
if (numModes) {
- newModes = malloc(numModes * sizeof(RRModePtr));
+ newModes = xallocarray(numModes, sizeof(RRModePtr));
if (!newModes)
return FALSE;
}
@@ -200,8 +200,8 @@ RROutputAddUserMode(RROutputPtr output, RRModePtr mode)
return BadMatch;
if (output->userModes)
- newModes = realloc(output->userModes,
- (output->numUserModes + 1) * sizeof(RRModePtr));
+ newModes = reallocarray(output->userModes,
+ output->numUserModes + 1, sizeof(RRModePtr));
else
newModes = malloc(sizeof(RRModePtr));
if (!newModes)
@@ -256,7 +256,7 @@ RROutputSetCrtcs(RROutputPtr output, RRCrtcPtr * crtcs, int numCrtcs)
return TRUE;
}
if (numCrtcs) {
- newCrtcs = malloc(numCrtcs * sizeof(RRCrtcPtr));
+ newCrtcs = xallocarray(numCrtcs, sizeof(RRCrtcPtr));
if (!newCrtcs)
return FALSE;
}
diff --git a/randr/rrproperty.c b/randr/rrproperty.c
index e385e15..e56626c 100644
--- a/randr/rrproperty.c
+++ b/randr/rrproperty.c
@@ -140,7 +140,6 @@ RRChangeOutputProperty(RROutputPtr output, Atom property, Atom type,
RRPropertyPtr prop;
rrScrPrivPtr pScrPriv = rrGetScrPriv(output->pScreen);
int size_in_bytes;
- int total_size;
unsigned long total_len;
RRPropertyValuePtr prop_value;
RRPropertyValueRec new_value;
@@ -180,9 +179,8 @@ RRChangeOutputProperty(RROutputPtr output, Atom property, Atom type,
if (mode == PropModeReplace || len > 0) {
void *new_data = NULL, *old_data = NULL;
- total_size = total_len * size_in_bytes;
- new_value.data = (void *) malloc(total_size);
- if (!new_value.data && total_size) {
+ new_value.data = xallocarray(total_len, size_in_bytes);
+ if (!new_value.data && total_len && size_in_bytes) {
if (add)
RRDestroyOutputProperty(prop);
return BadAlloc;
@@ -350,7 +348,7 @@ RRConfigureOutputProperty(RROutputPtr output, Atom property,
return BadMatch;
}
- new_values = malloc(num_values * sizeof(INT32));
+ new_values = xallocarray(num_values, sizeof(INT32));
if (!new_values && num_values) {
if (add)
RRDestroyOutputProperty(prop);
@@ -400,7 +398,7 @@ ProcRRListOutputProperties(ClientPtr client)
for (prop = output->properties; prop; prop = prop->next)
numProps++;
if (numProps)
- if (!(pAtoms = (Atom *) malloc(numProps * sizeof(Atom))))
+ if (!(pAtoms = xallocarray(numProps, sizeof(Atom))))
return BadAlloc;
rep = (xRRListOutputPropertiesReply) {
@@ -447,7 +445,7 @@ ProcRRQueryOutputProperty(ClientPtr client)
return BadName;
if (prop->num_valid) {
- extra = malloc(prop->num_valid * sizeof(INT32));
+ extra = xallocarray(prop->num_valid, sizeof(INT32));
if (!extra)
return BadAlloc;
}
diff --git a/randr/rrproviderproperty.c b/randr/rrproviderproperty.c
index ff2c614..b79c17f 100644
--- a/randr/rrproviderproperty.c
+++ b/randr/rrproviderproperty.c
@@ -350,7 +350,7 @@ RRConfigureProviderProperty(RRProviderPtr provider, Atom property,
return BadMatch;
}
- new_values = malloc(num_values * sizeof(INT32));
+ new_values = xallocarray(num_values, sizeof(INT32));
if (!new_values && num_values) {
if (add)
RRDestroyProviderProperty(prop);
@@ -400,7 +400,7 @@ ProcRRListProviderProperties(ClientPtr client)
for (prop = provider->properties; prop; prop = prop->next)
numProps++;
if (numProps)
- if (!(pAtoms = (Atom *) malloc(numProps * sizeof(Atom))))
+ if (!(pAtoms = xallocarray(numProps, sizeof(Atom))))
return BadAlloc;
rep = (xRRListProviderPropertiesReply) {
@@ -445,7 +445,7 @@ ProcRRQueryProviderProperty(ClientPtr client)
return BadName;
if (prop->num_valid) {
- extra = malloc(prop->num_valid * sizeof(INT32));
+ extra = xallocarray(prop->num_valid, sizeof(INT32));
if (!extra)
return BadAlloc;
}
diff --git a/randr/rrtransform.c b/randr/rrtransform.c
index c8a2749..6137f85 100644
--- a/randr/rrtransform.c
+++ b/randr/rrtransform.c
@@ -70,7 +70,7 @@ RRTransformSetFilter(RRTransformPtr dst,
xFixed *new_params;
if (nparams) {
- new_params = malloc(nparams * sizeof(xFixed));
+ new_params = xallocarray(nparams, sizeof(xFixed));
if (!new_params)
return FALSE;
memcpy(new_params, params, nparams * sizeof(xFixed));
diff --git a/record/record.c b/record/record.c
index 0a466e2..1caf3f1 100644
--- a/record/record.c
+++ b/record/record.c
@@ -1074,19 +1074,19 @@ RecordAddClientToRCAP(RecordClientsAndProtocolPtr pRCAP, XID clientspec)
{
if (pRCAP->numClients == pRCAP->sizeClients) {
if (pRCAP->clientIDsSeparatelyAllocated) {
- XID *pNewIDs = (XID *) realloc(pRCAP->pClientIDs,
- (pRCAP->sizeClients +
- CLIENT_ARRAY_GROWTH_INCREMENT) *
- sizeof(XID));
+ XID *pNewIDs =
+ reallocarray(pRCAP->pClientIDs,
+ pRCAP->sizeClients + CLIENT_ARRAY_GROWTH_INCREMENT,
+ sizeof(XID));
if (!pNewIDs)
return;
pRCAP->pClientIDs = pNewIDs;
pRCAP->sizeClients += CLIENT_ARRAY_GROWTH_INCREMENT;
}
else {
- XID *pNewIDs = (XID *) malloc((pRCAP->sizeClients +
- CLIENT_ARRAY_GROWTH_INCREMENT) *
- sizeof(XID));
+ XID *pNewIDs =
+ xallocarray(pRCAP->sizeClients + CLIENT_ARRAY_GROWTH_INCREMENT,
+ sizeof(XID));
if (!pNewIDs)
return;
memcpy(pNewIDs, pRCAP->pClientIDs, pRCAP->numClients * sizeof(XID));
@@ -1217,7 +1217,7 @@ RecordCanonicalizeClientSpecifiers(XID *pClientspecs, int *pNumClientspecs,
for (i = 0; i < numClients; i++) {
if (pClientspecs[i] == XRecordAllClients || pClientspecs[i] == XRecordCurrentClients) { /* expand All/Current */
int j, nc;
- XID *pCanon = (XID *) malloc(sizeof(XID) * (currentMaxClients + 1));
+ XID *pCanon = xallocarray(currentMaxClients + 1, sizeof(XID));
if (!pCanon)
return NULL;
@@ -1421,8 +1421,7 @@ static int
RecordAllocIntervals(SetInfoPtr psi, int nIntervals)
{
assert(!psi->intervals);
- psi->intervals = (RecordSetInterval *)
- malloc(nIntervals * sizeof(RecordSetInterval));
+ psi->intervals = xallocarray(nIntervals, sizeof(RecordSetInterval));
if (!psi->intervals)
return BadAlloc;
memset(psi->intervals, 0, nIntervals * sizeof(RecordSetInterval));
@@ -1584,7 +1583,7 @@ RecordRegisterClients(RecordContextPtr pContext, ClientPtr client,
* range for extension replies.
*/
maxSets = PREDEFSETS + 2 * stuff->nRanges;
- si = (SetInfoPtr) malloc(sizeof(SetInfoRec) * maxSets);
+ si = xallocarray(maxSets, sizeof(SetInfoRec));
if (!si) {
err = BadAlloc;
goto bailout;
@@ -1853,8 +1852,8 @@ ProcRecordCreateContext(ClientPtr client)
/* make sure there is room in ppAllContexts to store the new context */
- ppNewAllContexts = (RecordContextPtr *)
- realloc(ppAllContexts, sizeof(RecordContextPtr) * (numContexts + 1));
+ ppNewAllContexts =
+ reallocarray(ppAllContexts, numContexts + 1, sizeof(RecordContextPtr));
if (!ppNewAllContexts)
goto bailout;
ppAllContexts = ppNewAllContexts;
@@ -1971,8 +1970,7 @@ RecordAllocRanges(GetContextRangeInfoPtr pri, int nRanges)
#define SZINCR 8
newsize = max(pri->size + SZINCR, nRanges);
- pNewRange = (xRecordRange *) realloc(pri->pRanges,
- newsize * sizeof(xRecordRange));
+ pNewRange = reallocarray(pri->pRanges, newsize, sizeof(xRecordRange));
if (!pNewRange)
return BadAlloc;
@@ -2150,9 +2148,7 @@ ProcRecordGetContext(ClientPtr client)
/* allocate and initialize space for record range info */
- pRangeInfo =
- (GetContextRangeInfoPtr) malloc(nRCAPs *
- sizeof(GetContextRangeInfoRec));
+ pRangeInfo = xallocarray(nRCAPs, sizeof(GetContextRangeInfoRec));
if (!pRangeInfo && nRCAPs > 0)
return BadAlloc;
for (i = 0; i < nRCAPs; i++) {
@@ -2733,7 +2729,8 @@ RecordAClientStateChange(CallbackListPtr *pcbl, void *nulldata,
/* RecordDisableContext modifies contents of ppAllContexts. */
numContextsCopy = numContexts;
- ppAllContextsCopy = malloc(numContextsCopy * sizeof(RecordContextPtr));
+ ppAllContextsCopy = xallocarray(numContextsCopy,
+ sizeof(RecordContextPtr));
assert(ppAllContextsCopy);
memcpy(ppAllContextsCopy, ppAllContexts,
numContextsCopy * sizeof(RecordContextPtr));
diff --git a/record/set.c b/record/set.c
index 34faa61..e0db385 100644
--- a/record/set.c
+++ b/record/set.c
@@ -303,9 +303,7 @@ IntervalListCreateSet(RecordSetInterval * pIntervals, int nIntervals,
CARD16 first;
if (nIntervals > 0) {
- stackIntervals =
- (RecordSetInterval *) malloc(sizeof(RecordSetInterval) *
- nIntervals);
+ stackIntervals = xallocarray(nIntervals, sizeof(RecordSetInterval));
if (!stackIntervals)
return NULL;
diff --git a/render/filter.c b/render/filter.c
index 019ea7f..2741f40 100644
--- a/render/filter.c
+++ b/render/filter.c
@@ -67,7 +67,7 @@ PictureGetFilterId(const char *filter, int len, Bool makeit)
memcpy(name, filter, len);
name[len] = '\0';
if (filterNames)
- names = realloc(filterNames, (nfilterNames + 1) * sizeof(char *));
+ names = reallocarray(filterNames, nfilterNames + 1, sizeof(char *));
else
names = malloc(sizeof(char *));
if (!names) {
@@ -145,7 +145,7 @@ PictureAddFilter(ScreenPtr pScreen,
return -1;
if (ps->filters)
filters =
- realloc(ps->filters, (ps->nfilters + 1) * sizeof(PictFilterRec));
+ reallocarray(ps->filters, ps->nfilters + 1, sizeof(PictFilterRec));
else
filters = malloc(sizeof(PictFilterRec));
if (!filters)
@@ -177,9 +177,9 @@ PictureSetFilterAlias(ScreenPtr pScreen, const char *filter, const char *alias)
PictFilterAliasPtr aliases;
if (ps->filterAliases)
- aliases = realloc(ps->filterAliases,
- (ps->nfilterAliases + 1) *
- sizeof(PictFilterAliasRec));
+ aliases = reallocarray(ps->filterAliases,
+ ps->nfilterAliases + 1,
+ sizeof(PictFilterAliasRec));
else
aliases = malloc(sizeof(PictFilterAliasRec));
if (!aliases)
@@ -336,7 +336,7 @@ SetPicturePictFilter(PicturePtr pPicture, PictFilterPtr pFilter,
return BadMatch;
if (nparams != pPicture->filter_nparams) {
- xFixed *new_params = malloc(nparams * sizeof(xFixed));
+ xFixed *new_params = xallocarray(nparams, sizeof(xFixed));
if (!new_params && nparams)
return BadAlloc;
diff --git a/render/miindex.c b/render/miindex.c
index 0375e8f..4119eef 100644
--- a/render/miindex.c
+++ b/render/miindex.c
@@ -254,7 +254,7 @@ miInitIndexed(ScreenPtr pScreen, PictFormatPtr pFormat)
return FALSE;
pFormat->index.nvalues = num;
- pFormat->index.pValues = malloc(num * sizeof(xIndexValue));
+ pFormat->index.pValues = xallocarray(num, sizeof(xIndexValue));
if (!pFormat->index.pValues) {
free(pIndexed);
return FALSE;
diff --git a/render/mipict.c b/render/mipict.c
index a725104..2571fda 100644
--- a/render/mipict.c
+++ b/render/mipict.c
@@ -510,7 +510,7 @@ miTriStrip(CARD8 op,
int ntri;
ntri = npoints - 2;
- tris = malloc(ntri * sizeof(xTriangle));
+ tris = xallocarray(ntri, sizeof(xTriangle));
if (!tris)
return;
@@ -535,7 +535,7 @@ miTriFan(CARD8 op,
int ntri;
ntri = npoints - 2;
- tris = malloc(ntri * sizeof(xTriangle));
+ tris = xallocarray(ntri, sizeof(xTriangle));
if (!tris)
return;
diff --git a/render/picture.c b/render/picture.c
index 6ff31ba..60517a4 100644
--- a/render/picture.c
+++ b/render/picture.c
@@ -837,7 +837,7 @@ initGradient(SourcePictPtr pGradient, int stopCount,
dpos = stopPoints[i];
}
- pGradient->gradient.stops = malloc(stopCount * sizeof(PictGradientStop));
+ pGradient->gradient.stops = xallocarray(stopCount, sizeof(PictGradientStop));
if (!pGradient->gradient.stops) {
*error = BadAlloc;
return;
diff --git a/render/render.c b/render/render.c
index 723f380..88d8a26 100644
--- a/render/render.c
+++ b/render/render.c
@@ -1318,14 +1318,14 @@ ProcRenderCompositeGlyphs(ClientPtr client)
if (nglyph <= NLOCALGLYPH)
glyphsBase = glyphsLocal;
else {
- glyphsBase = (GlyphPtr *) malloc(nglyph * sizeof(GlyphPtr));
+ glyphsBase = xallocarray(nglyph, sizeof(GlyphPtr));
if (!glyphsBase)
return BadAlloc;
}
if (nlist <= NLOCALDELTA)
listsBase = listsLocal;
else {
- listsBase = (GlyphListPtr) malloc(nlist * sizeof(GlyphListRec));
+ listsBase = xallocarray(nlist, sizeof(GlyphListRec));
if (!listsBase) {
rc = BadAlloc;
goto bail;
@@ -1793,7 +1793,7 @@ ProcRenderCreateAnimCursor(ClientPtr client)
ncursor =
(client->req_len -
(bytes_to_int32(sizeof(xRenderCreateAnimCursorReq)))) >> 1;
- cursors = malloc(ncursor * (sizeof(CursorPtr) + sizeof(CARD32)));
+ cursors = xallocarray(ncursor, sizeof(CursorPtr) + sizeof(CARD32));
if (!cursors)
return BadAlloc;
deltas = (CARD32 *) (cursors + ncursor);
diff --git a/xfixes/region.c b/xfixes/region.c
index 4492f12..dd74d7f 100644
--- a/xfixes/region.c
+++ b/xfixes/region.c
@@ -777,7 +777,7 @@ ProcXFixesExpandRegion(ClientPtr client)
nBoxes = RegionNumRects(pSource);
pSrc = RegionRects(pSource);
if (nBoxes) {
- pTmp = malloc(nBoxes * sizeof(BoxRec));
+ pTmp = xallocarray(nBoxes, sizeof(BoxRec));
if (!pTmp)
return BadAlloc;
for (i = 0; i < nBoxes; i++) {
--
1.7.9.2
More information about the xorg-devel
mailing list