Skip to content

Commit

Permalink
Convert top level extensions to new *allocarray functions
Browse files Browse the repository at this point in the history
v2: remove now useless parentheses

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Reviewed-by: Matt Turner <mattst88@gmail.com>
  • Loading branch information
alanc committed Apr 21, 2015
1 parent b9e665c commit 1c56ac6
Show file tree
Hide file tree
Showing 34 changed files with 111 additions and 122 deletions.
4 changes: 2 additions & 2 deletions Xext/hashtable.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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]);
Expand Down
10 changes: 5 additions & 5 deletions Xext/panoramiX.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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));

Expand Down
19 changes: 9 additions & 10 deletions Xext/panoramiXprocs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

Expand Down Expand Up @@ -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) {

Expand Down Expand Up @@ -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) {

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {

Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion Xext/saver.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion Xext/shape.c
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand Down
4 changes: 2 additions & 2 deletions Xext/sync.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion Xext/xcmisc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions Xext/xf86bigfont.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion Xext/xres.c
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand Down
2 changes: 1 addition & 1 deletion Xext/xselinux_label.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion Xext/xvmain.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions Xi/exevents.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion Xi/getprop.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 3 additions & 5 deletions Xi/xiproperty.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions composite/compinit.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down
14 changes: 6 additions & 8 deletions dbe/dbe.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion dbe/midbe.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
}

Expand Down
6 changes: 3 additions & 3 deletions pseudoramiX/pseudoramiX.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
14 changes: 7 additions & 7 deletions randr/rrcrtc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down
Loading

0 comments on commit 1c56ac6

Please sign in to comment.