Convert top level extensions to new *allocarray functions

v2: remove now useless parentheses

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Reviewed-by: Matt Turner <mattst88@gmail.com>
This commit is contained in:
Alan Coopersmith 2015-03-21 13:42:12 -07:00
parent b9e665c8b2
commit 1c56ac63c0
34 changed files with 111 additions and 122 deletions

View File

@ -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]);

View File

@ -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));

View File

@ -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);

View File

@ -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;

View File

@ -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++) {

View File

@ -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;

View File

@ -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;
}

View File

@ -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);

View File

@ -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++) {

View File

@ -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));

View File

@ -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;

View File

@ -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,

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;
}

View File

@ -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 */
}

View File

@ -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);

View File

@ -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;
}

View File

@ -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++];

View File

@ -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;

View File

@ -494,8 +494,9 @@ RRMonitorAdd(ClientPtr client, ScreenPtr screen, RRMonitorPtr monitor)
* needs to not have any side-effects on failure
*/
if (pScrPriv->numMonitors)
monitors = realloc(pScrPriv->monitors,
(pScrPriv->numMonitors + 1) * sizeof (RRMonitorPtr));
monitors = reallocarray(pScrPriv->monitors,
pScrPriv->numMonitors + 1,
sizeof (RRMonitorPtr));
else
monitors = malloc(sizeof (RRMonitorPtr));

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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));

View File

@ -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));

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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);

View File

@ -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++) {