mirror of
https://github.com/X11Libre/xserver.git
synced 2026-04-14 17:18:09 +00:00
(1823) xext: replace xallocarray() by calloc()
Only key difference that calloc(), in contrast to rellocarray(),
is zero-initializing. The overhead is hard to measure on today's
machines, and it's safer programming practise to always allocate
zero-initialized, so one can't forget to do it explicitly.
Cocci rule:
@@
expression COUNT;
expression LEN;
@@
- xallocarray(COUNT,LEN)
+ calloc(COUNT,LEN)
Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
This commit is contained in:
@@ -52,7 +52,7 @@ ht_create(int keySize,
|
||||
ht->elements = 0;
|
||||
ht->bucketBits = INITHASHSIZE;
|
||||
numBuckets = 1 << ht->bucketBits;
|
||||
ht->buckets = xallocarray(numBuckets, sizeof(*ht->buckets));
|
||||
ht->buckets = calloc(numBuckets, sizeof(*ht->buckets));
|
||||
ht->cdata = cdata;
|
||||
|
||||
if (ht->buckets) {
|
||||
@@ -93,7 +93,7 @@ double_size(HashTable ht)
|
||||
int newNumBuckets = 1 << newBucketBits;
|
||||
int c;
|
||||
|
||||
newBuckets = xallocarray(newNumBuckets, sizeof(*ht->buckets));
|
||||
newBuckets = calloc(newNumBuckets, sizeof(*ht->buckets));
|
||||
if (newBuckets) {
|
||||
for (c = 0; c < newNumBuckets; ++c) {
|
||||
xorg_list_init(&newBuckets[c]);
|
||||
|
||||
@@ -1396,7 +1396,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 = xallocarray(npoint, sizeof(xPoint));
|
||||
origPts = calloc(npoint, sizeof(xPoint));
|
||||
memcpy((char *) origPts, (char *) &stuff[1], npoint * sizeof(xPoint));
|
||||
FOR_NSCREENS_FORWARD(j) {
|
||||
|
||||
@@ -1461,7 +1461,7 @@ PanoramiXPolyLine(ClientPtr client)
|
||||
isRoot = IS_ROOT_DRAWABLE(draw);
|
||||
npoint = bytes_to_int32((client->req_len << 2) - sizeof(xPolyLineReq));
|
||||
if (npoint > 0) {
|
||||
origPts = xallocarray(npoint, sizeof(xPoint));
|
||||
origPts = calloc(npoint, sizeof(xPoint));
|
||||
memcpy((char *) origPts, (char *) &stuff[1], npoint * sizeof(xPoint));
|
||||
FOR_NSCREENS_FORWARD(j) {
|
||||
|
||||
@@ -1530,7 +1530,7 @@ PanoramiXPolySegment(ClientPtr client)
|
||||
return BadLength;
|
||||
nsegs >>= 3;
|
||||
if (nsegs > 0) {
|
||||
origSegs = xallocarray(nsegs, sizeof(xSegment));
|
||||
origSegs = calloc(nsegs, sizeof(xSegment));
|
||||
memcpy((char *) origSegs, (char *) &stuff[1], nsegs * sizeof(xSegment));
|
||||
FOR_NSCREENS_FORWARD(j) {
|
||||
|
||||
@@ -1598,7 +1598,7 @@ PanoramiXPolyRectangle(ClientPtr client)
|
||||
return BadLength;
|
||||
nrects >>= 3;
|
||||
if (nrects > 0) {
|
||||
origRecs = xallocarray(nrects, sizeof(xRectangle));
|
||||
origRecs = calloc(nrects, sizeof(xRectangle));
|
||||
memcpy((char *) origRecs, (char *) &stuff[1],
|
||||
nrects * sizeof(xRectangle));
|
||||
FOR_NSCREENS_FORWARD(j) {
|
||||
@@ -1665,7 +1665,7 @@ PanoramiXPolyArc(ClientPtr client)
|
||||
return BadLength;
|
||||
narcs /= sizeof(xArc);
|
||||
if (narcs > 0) {
|
||||
origArcs = xallocarray(narcs, sizeof(xArc));
|
||||
origArcs = calloc(narcs, sizeof(xArc));
|
||||
memcpy((char *) origArcs, (char *) &stuff[1], narcs * sizeof(xArc));
|
||||
FOR_NSCREENS_FORWARD(j) {
|
||||
|
||||
@@ -1727,7 +1727,7 @@ PanoramiXFillPoly(ClientPtr client)
|
||||
|
||||
count = bytes_to_int32((client->req_len << 2) - sizeof(xFillPolyReq));
|
||||
if (count > 0) {
|
||||
locPts = xallocarray(count, sizeof(DDXPointRec));
|
||||
locPts = calloc(count, sizeof(DDXPointRec));
|
||||
memcpy((char *) locPts, (char *) &stuff[1],
|
||||
count * sizeof(DDXPointRec));
|
||||
FOR_NSCREENS_FORWARD(j) {
|
||||
@@ -1796,7 +1796,7 @@ PanoramiXPolyFillRectangle(ClientPtr client)
|
||||
return BadLength;
|
||||
things >>= 3;
|
||||
if (things > 0) {
|
||||
origRects = xallocarray(things, sizeof(xRectangle));
|
||||
origRects = calloc(things, sizeof(xRectangle));
|
||||
memcpy((char *) origRects, (char *) &stuff[1],
|
||||
things * sizeof(xRectangle));
|
||||
FOR_NSCREENS_FORWARD(j) {
|
||||
@@ -1863,7 +1863,7 @@ PanoramiXPolyFillArc(ClientPtr client)
|
||||
return BadLength;
|
||||
narcs /= sizeof(xArc);
|
||||
if (narcs > 0) {
|
||||
origArcs = xallocarray(narcs, sizeof(xArc));
|
||||
origArcs = calloc(narcs, sizeof(xArc));
|
||||
memcpy((char *) origArcs, (char *) &stuff[1], narcs * sizeof(xArc));
|
||||
FOR_NSCREENS_FORWARD(j) {
|
||||
|
||||
@@ -2049,7 +2049,7 @@ PanoramiXGetImage(ClientPtr client)
|
||||
if (linesPerBuf > h)
|
||||
linesPerBuf = h;
|
||||
}
|
||||
if (!(pBuf = xallocarray(linesPerBuf, widthBytesLine)))
|
||||
if (!(pBuf = calloc(linesPerBuf, widthBytesLine)))
|
||||
return BadAlloc;
|
||||
|
||||
WriteReplyToClient(client, sizeof(xGetImageReply), &xgi);
|
||||
|
||||
@@ -822,7 +822,7 @@ ScreenSaverSetAttributes(ClientPtr client, xScreenSaverSetAttributesReq *stuff)
|
||||
goto bail;
|
||||
}
|
||||
/* over allocate for override redirect */
|
||||
pAttr->values = values = xallocarray(len + 1, sizeof(unsigned long));
|
||||
pAttr->values = values = calloc(len + 1, sizeof(unsigned long));
|
||||
if (!values) {
|
||||
ret = BadAlloc;
|
||||
goto bail;
|
||||
|
||||
@@ -988,7 +988,7 @@ ProcShapeGetRectangles(ClientPtr client)
|
||||
|
||||
nrects = RegionNumRects(region);
|
||||
box = RegionRects(region);
|
||||
rects = xallocarray(nrects, sizeof(xRectangle));
|
||||
rects = calloc(nrects, sizeof(xRectangle));
|
||||
if (!rects && nrects)
|
||||
return BadAlloc;
|
||||
for (i = 0; i < nrects; i++, box++) {
|
||||
|
||||
@@ -650,7 +650,7 @@ SyncAwaitTriggerFired(SyncTrigger * pTrigger)
|
||||
|
||||
pAwaitUnion = (SyncAwaitUnion *) pAwait->pHeader;
|
||||
numwaits = pAwaitUnion->header.num_waitconditions;
|
||||
ppAwait = xallocarray(numwaits, sizeof(SyncAwait *));
|
||||
ppAwait = calloc(numwaits, sizeof(SyncAwait *));
|
||||
if (!ppAwait)
|
||||
goto bail;
|
||||
|
||||
@@ -1547,7 +1547,7 @@ SyncAwaitPrologue(ClientPtr client, int items)
|
||||
/* all the memory for the entire await list is allocated
|
||||
* here in one chunk
|
||||
*/
|
||||
pAwaitUnion = xallocarray(items + 1, sizeof(SyncAwaitUnion));
|
||||
pAwaitUnion = calloc(items + 1, sizeof(SyncAwaitUnion));
|
||||
if (!pAwaitUnion)
|
||||
return NULL;
|
||||
|
||||
|
||||
@@ -1198,11 +1198,11 @@ ProcVidModeGetMonitor(ClientPtr client)
|
||||
pad_to_int32(rep.modelLength));
|
||||
rep.nhsync = nHsync;
|
||||
rep.nvsync = nVrefresh;
|
||||
hsyncdata = xallocarray(nHsync, sizeof(CARD32));
|
||||
hsyncdata = calloc(nHsync, sizeof(CARD32));
|
||||
if (!hsyncdata) {
|
||||
return BadAlloc;
|
||||
}
|
||||
vsyncdata = xallocarray(nVrefresh, sizeof(CARD32));
|
||||
vsyncdata = calloc(nVrefresh, sizeof(CARD32));
|
||||
|
||||
if (!vsyncdata) {
|
||||
free(hsyncdata);
|
||||
@@ -1520,7 +1520,7 @@ ProcVidModeGetGammaRamp(ClientPtr client)
|
||||
length = (stuff->size + 1) & ~1;
|
||||
|
||||
if (stuff->size) {
|
||||
if (!(ramp = xallocarray(length, 3 * sizeof(CARD16))))
|
||||
if (!(ramp = calloc(length, 3 * sizeof(CARD16))))
|
||||
return BadAlloc;
|
||||
ramplen = length * 3 * sizeof(CARD16);
|
||||
|
||||
|
||||
@@ -99,7 +99,7 @@ ProcXCMiscGetXIDList(ClientPtr client)
|
||||
if (stuff->count > UINT32_MAX / sizeof(XID))
|
||||
return BadAlloc;
|
||||
|
||||
pids = xallocarray(stuff->count, sizeof(XID));
|
||||
pids = calloc(stuff->count, sizeof(XID));
|
||||
if (!pids) {
|
||||
return BadAlloc;
|
||||
}
|
||||
|
||||
@@ -390,7 +390,7 @@ ProcXF86BigfontQueryFont(ClientPtr client)
|
||||
}
|
||||
else {
|
||||
#endif
|
||||
pCI = xallocarray(nCharInfos, sizeof(xCharInfo));
|
||||
pCI = calloc(nCharInfos, sizeof(xCharInfo));
|
||||
if (!pCI)
|
||||
return BadAlloc;
|
||||
#ifdef MITSHM
|
||||
@@ -452,7 +452,7 @@ ProcXF86BigfontQueryFont(ClientPtr client)
|
||||
if (hashModulus > nCharInfos + 1)
|
||||
hashModulus = nCharInfos + 1;
|
||||
|
||||
tmp = xallocarray(4 * nCharInfos + 1, sizeof(CARD16));
|
||||
tmp = calloc(4 * nCharInfos + 1, sizeof(CARD16));
|
||||
if (!tmp) {
|
||||
if (!pDesc)
|
||||
free(pCI);
|
||||
|
||||
@@ -225,7 +225,7 @@ ProcXResQueryClients(ClientPtr client)
|
||||
|
||||
REQUEST_SIZE_MATCH(xXResQueryClientsReq);
|
||||
|
||||
current_clients = xallocarray(currentMaxClients, sizeof(int));
|
||||
current_clients = calloc(currentMaxClients, sizeof(int));
|
||||
|
||||
num_clients = 0;
|
||||
for (i = 0; i < currentMaxClients; i++) {
|
||||
|
||||
@@ -1082,7 +1082,7 @@ XvFillColorKey(DrawablePtr pDraw, CARD32 key, RegionPtr region)
|
||||
(void) ChangeGC(NullClient, gc, GCForeground | GCSubwindowMode, pval);
|
||||
ValidateGC(pDraw, gc);
|
||||
|
||||
rects = xallocarray(nbox, sizeof(xRectangle));
|
||||
rects = calloc(nbox, sizeof(xRectangle));
|
||||
if (rects) {
|
||||
for (i = 0; i < nbox; i++, pbox++) {
|
||||
rects[i].x = pbox->x1 - pDraw->x;
|
||||
|
||||
Reference in New Issue
Block a user