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:
		
							parent
							
								
									32b3328e49
								
							
						
					
					
						commit
						0263bc7c32
					
				|  | @ -52,7 +52,7 @@ ht_create(int             keySize, | ||||||
|     ht->elements = 0; |     ht->elements = 0; | ||||||
|     ht->bucketBits = INITHASHSIZE; |     ht->bucketBits = INITHASHSIZE; | ||||||
|     numBuckets = 1 << ht->bucketBits; |     numBuckets = 1 << ht->bucketBits; | ||||||
|     ht->buckets = xallocarray(numBuckets, sizeof(*ht->buckets)); |     ht->buckets = calloc(numBuckets, sizeof(*ht->buckets)); | ||||||
|     ht->cdata = cdata; |     ht->cdata = cdata; | ||||||
| 
 | 
 | ||||||
|     if (ht->buckets) { |     if (ht->buckets) { | ||||||
|  | @ -93,7 +93,7 @@ double_size(HashTable ht) | ||||||
|     int newNumBuckets = 1 << newBucketBits; |     int newNumBuckets = 1 << newBucketBits; | ||||||
|     int c; |     int c; | ||||||
| 
 | 
 | ||||||
|     newBuckets = xallocarray(newNumBuckets, sizeof(*ht->buckets)); |     newBuckets = calloc(newNumBuckets, sizeof(*ht->buckets)); | ||||||
|     if (newBuckets) { |     if (newBuckets) { | ||||||
|         for (c = 0; c < newNumBuckets; ++c) { |         for (c = 0; c < newNumBuckets; ++c) { | ||||||
|             xorg_list_init(&newBuckets[c]); |             xorg_list_init(&newBuckets[c]); | ||||||
|  |  | ||||||
|  | @ -1397,7 +1397,7 @@ PanoramiXPolyPoint(ClientPtr client) | ||||||
|     isRoot = (draw->type == XRT_WINDOW) && draw->u.win.root; |     isRoot = (draw->type == XRT_WINDOW) && draw->u.win.root; | ||||||
|     npoint = bytes_to_int32((client->req_len << 2) - sizeof(xPolyPointReq)); |     npoint = bytes_to_int32((client->req_len << 2) - sizeof(xPolyPointReq)); | ||||||
|     if (npoint > 0) { |     if (npoint > 0) { | ||||||
|         origPts = xallocarray(npoint, sizeof(xPoint)); |         origPts = calloc(npoint, sizeof(xPoint)); | ||||||
|         memcpy((char *) origPts, (char *) &stuff[1], npoint * sizeof(xPoint)); |         memcpy((char *) origPts, (char *) &stuff[1], npoint * sizeof(xPoint)); | ||||||
|         FOR_NSCREENS_FORWARD(j) { |         FOR_NSCREENS_FORWARD(j) { | ||||||
| 
 | 
 | ||||||
|  | @ -1462,7 +1462,7 @@ PanoramiXPolyLine(ClientPtr client) | ||||||
|     isRoot = IS_ROOT_DRAWABLE(draw); |     isRoot = IS_ROOT_DRAWABLE(draw); | ||||||
|     npoint = bytes_to_int32((client->req_len << 2) - sizeof(xPolyLineReq)); |     npoint = bytes_to_int32((client->req_len << 2) - sizeof(xPolyLineReq)); | ||||||
|     if (npoint > 0) { |     if (npoint > 0) { | ||||||
|         origPts = xallocarray(npoint, sizeof(xPoint)); |         origPts = calloc(npoint, sizeof(xPoint)); | ||||||
|         memcpy((char *) origPts, (char *) &stuff[1], npoint * sizeof(xPoint)); |         memcpy((char *) origPts, (char *) &stuff[1], npoint * sizeof(xPoint)); | ||||||
|         FOR_NSCREENS_FORWARD(j) { |         FOR_NSCREENS_FORWARD(j) { | ||||||
| 
 | 
 | ||||||
|  | @ -1531,7 +1531,7 @@ PanoramiXPolySegment(ClientPtr client) | ||||||
|         return BadLength; |         return BadLength; | ||||||
|     nsegs >>= 3; |     nsegs >>= 3; | ||||||
|     if (nsegs > 0) { |     if (nsegs > 0) { | ||||||
|         origSegs = xallocarray(nsegs, sizeof(xSegment)); |         origSegs = calloc(nsegs, sizeof(xSegment)); | ||||||
|         memcpy((char *) origSegs, (char *) &stuff[1], nsegs * sizeof(xSegment)); |         memcpy((char *) origSegs, (char *) &stuff[1], nsegs * sizeof(xSegment)); | ||||||
|         FOR_NSCREENS_FORWARD(j) { |         FOR_NSCREENS_FORWARD(j) { | ||||||
| 
 | 
 | ||||||
|  | @ -1599,7 +1599,7 @@ PanoramiXPolyRectangle(ClientPtr client) | ||||||
|         return BadLength; |         return BadLength; | ||||||
|     nrects >>= 3; |     nrects >>= 3; | ||||||
|     if (nrects > 0) { |     if (nrects > 0) { | ||||||
|         origRecs = xallocarray(nrects, sizeof(xRectangle)); |         origRecs = calloc(nrects, sizeof(xRectangle)); | ||||||
|         memcpy((char *) origRecs, (char *) &stuff[1], |         memcpy((char *) origRecs, (char *) &stuff[1], | ||||||
|                nrects * sizeof(xRectangle)); |                nrects * sizeof(xRectangle)); | ||||||
|         FOR_NSCREENS_FORWARD(j) { |         FOR_NSCREENS_FORWARD(j) { | ||||||
|  | @ -1666,7 +1666,7 @@ PanoramiXPolyArc(ClientPtr client) | ||||||
|         return BadLength; |         return BadLength; | ||||||
|     narcs /= sizeof(xArc); |     narcs /= sizeof(xArc); | ||||||
|     if (narcs > 0) { |     if (narcs > 0) { | ||||||
|         origArcs = xallocarray(narcs, sizeof(xArc)); |         origArcs = calloc(narcs, sizeof(xArc)); | ||||||
|         memcpy((char *) origArcs, (char *) &stuff[1], narcs * sizeof(xArc)); |         memcpy((char *) origArcs, (char *) &stuff[1], narcs * sizeof(xArc)); | ||||||
|         FOR_NSCREENS_FORWARD(j) { |         FOR_NSCREENS_FORWARD(j) { | ||||||
| 
 | 
 | ||||||
|  | @ -1728,7 +1728,7 @@ PanoramiXFillPoly(ClientPtr client) | ||||||
| 
 | 
 | ||||||
|     count = bytes_to_int32((client->req_len << 2) - sizeof(xFillPolyReq)); |     count = bytes_to_int32((client->req_len << 2) - sizeof(xFillPolyReq)); | ||||||
|     if (count > 0) { |     if (count > 0) { | ||||||
|         locPts = xallocarray(count, sizeof(DDXPointRec)); |         locPts = calloc(count, sizeof(DDXPointRec)); | ||||||
|         memcpy((char *) locPts, (char *) &stuff[1], |         memcpy((char *) locPts, (char *) &stuff[1], | ||||||
|                count * sizeof(DDXPointRec)); |                count * sizeof(DDXPointRec)); | ||||||
|         FOR_NSCREENS_FORWARD(j) { |         FOR_NSCREENS_FORWARD(j) { | ||||||
|  | @ -1797,7 +1797,7 @@ PanoramiXPolyFillRectangle(ClientPtr client) | ||||||
|         return BadLength; |         return BadLength; | ||||||
|     things >>= 3; |     things >>= 3; | ||||||
|     if (things > 0) { |     if (things > 0) { | ||||||
|         origRects = xallocarray(things, sizeof(xRectangle)); |         origRects = calloc(things, sizeof(xRectangle)); | ||||||
|         memcpy((char *) origRects, (char *) &stuff[1], |         memcpy((char *) origRects, (char *) &stuff[1], | ||||||
|                things * sizeof(xRectangle)); |                things * sizeof(xRectangle)); | ||||||
|         FOR_NSCREENS_FORWARD(j) { |         FOR_NSCREENS_FORWARD(j) { | ||||||
|  | @ -1864,7 +1864,7 @@ PanoramiXPolyFillArc(ClientPtr client) | ||||||
|         return BadLength; |         return BadLength; | ||||||
|     narcs /= sizeof(xArc); |     narcs /= sizeof(xArc); | ||||||
|     if (narcs > 0) { |     if (narcs > 0) { | ||||||
|         origArcs = xallocarray(narcs, sizeof(xArc)); |         origArcs = calloc(narcs, sizeof(xArc)); | ||||||
|         memcpy((char *) origArcs, (char *) &stuff[1], narcs * sizeof(xArc)); |         memcpy((char *) origArcs, (char *) &stuff[1], narcs * sizeof(xArc)); | ||||||
|         FOR_NSCREENS_FORWARD(j) { |         FOR_NSCREENS_FORWARD(j) { | ||||||
| 
 | 
 | ||||||
|  | @ -2050,7 +2050,7 @@ PanoramiXGetImage(ClientPtr client) | ||||||
|         if (linesPerBuf > h) |         if (linesPerBuf > h) | ||||||
|             linesPerBuf = h; |             linesPerBuf = h; | ||||||
|     } |     } | ||||||
|     if (!(pBuf = xallocarray(linesPerBuf, widthBytesLine))) |     if (!(pBuf = calloc(linesPerBuf, widthBytesLine))) | ||||||
|         return BadAlloc; |         return BadAlloc; | ||||||
| 
 | 
 | ||||||
|     WriteReplyToClient(client, sizeof(xGetImageReply), &xgi); |     WriteReplyToClient(client, sizeof(xGetImageReply), &xgi); | ||||||
|  |  | ||||||
|  | @ -828,7 +828,7 @@ ScreenSaverSetAttributes(ClientPtr client, xScreenSaverSetAttributesReq *stuff) | ||||||
|         goto bail; |         goto bail; | ||||||
|     } |     } | ||||||
|     /* over allocate for override redirect */ |     /* 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) { |     if (!values) { | ||||||
|         ret = BadAlloc; |         ret = BadAlloc; | ||||||
|         goto bail; |         goto bail; | ||||||
|  |  | ||||||
|  | @ -991,7 +991,7 @@ ProcShapeGetRectangles(ClientPtr client) | ||||||
| 
 | 
 | ||||||
|         nrects = RegionNumRects(region); |         nrects = RegionNumRects(region); | ||||||
|         box = RegionRects(region); |         box = RegionRects(region); | ||||||
|         rects = xallocarray(nrects, sizeof(xRectangle)); |         rects = calloc(nrects, sizeof(xRectangle)); | ||||||
|         if (!rects && nrects) |         if (!rects && nrects) | ||||||
|             return BadAlloc; |             return BadAlloc; | ||||||
|         for (i = 0; i < nrects; i++, box++) { |         for (i = 0; i < nrects; i++, box++) { | ||||||
|  |  | ||||||
|  | @ -650,7 +650,7 @@ SyncAwaitTriggerFired(SyncTrigger * pTrigger) | ||||||
| 
 | 
 | ||||||
|     pAwaitUnion = (SyncAwaitUnion *) pAwait->pHeader; |     pAwaitUnion = (SyncAwaitUnion *) pAwait->pHeader; | ||||||
|     numwaits = pAwaitUnion->header.num_waitconditions; |     numwaits = pAwaitUnion->header.num_waitconditions; | ||||||
|     ppAwait = xallocarray(numwaits, sizeof(SyncAwait *)); |     ppAwait = calloc(numwaits, sizeof(SyncAwait *)); | ||||||
|     if (!ppAwait) |     if (!ppAwait) | ||||||
|         goto bail; |         goto bail; | ||||||
| 
 | 
 | ||||||
|  | @ -1547,7 +1547,7 @@ SyncAwaitPrologue(ClientPtr client, int items) | ||||||
|     /*  all the memory for the entire await list is allocated
 |     /*  all the memory for the entire await list is allocated
 | ||||||
|      *  here in one chunk |      *  here in one chunk | ||||||
|      */ |      */ | ||||||
|     pAwaitUnion = xallocarray(items + 1, sizeof(SyncAwaitUnion)); |     pAwaitUnion = calloc(items + 1, sizeof(SyncAwaitUnion)); | ||||||
|     if (!pAwaitUnion) |     if (!pAwaitUnion) | ||||||
|         return NULL; |         return NULL; | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -1198,11 +1198,11 @@ ProcVidModeGetMonitor(ClientPtr client) | ||||||
|                        pad_to_int32(rep.modelLength)); |                        pad_to_int32(rep.modelLength)); | ||||||
|     rep.nhsync = nHsync; |     rep.nhsync = nHsync; | ||||||
|     rep.nvsync = nVrefresh; |     rep.nvsync = nVrefresh; | ||||||
|     hsyncdata = xallocarray(nHsync, sizeof(CARD32)); |     hsyncdata = calloc(nHsync, sizeof(CARD32)); | ||||||
|     if (!hsyncdata) { |     if (!hsyncdata) { | ||||||
|         return BadAlloc; |         return BadAlloc; | ||||||
|     } |     } | ||||||
|     vsyncdata = xallocarray(nVrefresh, sizeof(CARD32)); |     vsyncdata = calloc(nVrefresh, sizeof(CARD32)); | ||||||
| 
 | 
 | ||||||
|     if (!vsyncdata) { |     if (!vsyncdata) { | ||||||
|         free(hsyncdata); |         free(hsyncdata); | ||||||
|  | @ -1520,7 +1520,7 @@ ProcVidModeGetGammaRamp(ClientPtr client) | ||||||
|     length = (stuff->size + 1) & ~1; |     length = (stuff->size + 1) & ~1; | ||||||
| 
 | 
 | ||||||
|     if (stuff->size) { |     if (stuff->size) { | ||||||
|         if (!(ramp = xallocarray(length, 3 * sizeof(CARD16)))) |         if (!(ramp = calloc(length, 3 * sizeof(CARD16)))) | ||||||
|             return BadAlloc; |             return BadAlloc; | ||||||
|         ramplen = length * 3 * sizeof(CARD16); |         ramplen = length * 3 * sizeof(CARD16); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -99,7 +99,7 @@ ProcXCMiscGetXIDList(ClientPtr client) | ||||||
|     if (stuff->count > UINT32_MAX / sizeof(XID)) |     if (stuff->count > UINT32_MAX / sizeof(XID)) | ||||||
|         return BadAlloc; |         return BadAlloc; | ||||||
| 
 | 
 | ||||||
|     pids = xallocarray(stuff->count, sizeof(XID)); |     pids = calloc(stuff->count, sizeof(XID)); | ||||||
|     if (!pids) { |     if (!pids) { | ||||||
|         return BadAlloc; |         return BadAlloc; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  | @ -390,7 +390,7 @@ ProcXF86BigfontQueryFont(ClientPtr client) | ||||||
|             } |             } | ||||||
|             else { |             else { | ||||||
| #endif | #endif | ||||||
|                 pCI = xallocarray(nCharInfos, sizeof(xCharInfo)); |                 pCI = calloc(nCharInfos, sizeof(xCharInfo)); | ||||||
|                 if (!pCI) |                 if (!pCI) | ||||||
|                     return BadAlloc; |                     return BadAlloc; | ||||||
| #ifdef MITSHM | #ifdef MITSHM | ||||||
|  | @ -452,7 +452,7 @@ ProcXF86BigfontQueryFont(ClientPtr client) | ||||||
|             if (hashModulus > nCharInfos + 1) |             if (hashModulus > nCharInfos + 1) | ||||||
|                 hashModulus = nCharInfos + 1; |                 hashModulus = nCharInfos + 1; | ||||||
| 
 | 
 | ||||||
|             tmp = xallocarray(4 * nCharInfos + 1, sizeof(CARD16)); |             tmp = calloc(4 * nCharInfos + 1, sizeof(CARD16)); | ||||||
|             if (!tmp) { |             if (!tmp) { | ||||||
|                 if (!pDesc) |                 if (!pDesc) | ||||||
|                     free(pCI); |                     free(pCI); | ||||||
|  |  | ||||||
|  | @ -225,7 +225,7 @@ ProcXResQueryClients(ClientPtr client) | ||||||
| 
 | 
 | ||||||
|     REQUEST_SIZE_MATCH(xXResQueryClientsReq); |     REQUEST_SIZE_MATCH(xXResQueryClientsReq); | ||||||
| 
 | 
 | ||||||
|     current_clients = xallocarray(currentMaxClients, sizeof(int)); |     current_clients = calloc(currentMaxClients, sizeof(int)); | ||||||
| 
 | 
 | ||||||
|     num_clients = 0; |     num_clients = 0; | ||||||
|     for (i = 0; i < currentMaxClients; i++) { |     for (i = 0; i < currentMaxClients; i++) { | ||||||
|  |  | ||||||
|  | @ -1083,7 +1083,7 @@ XvFillColorKey(DrawablePtr pDraw, CARD32 key, RegionPtr region) | ||||||
|     (void) ChangeGC(NullClient, gc, GCForeground | GCSubwindowMode, pval); |     (void) ChangeGC(NullClient, gc, GCForeground | GCSubwindowMode, pval); | ||||||
|     ValidateGC(pDraw, gc); |     ValidateGC(pDraw, gc); | ||||||
| 
 | 
 | ||||||
|     rects = xallocarray(nbox, sizeof(xRectangle)); |     rects = calloc(nbox, sizeof(xRectangle)); | ||||||
|     if (rects) { |     if (rects) { | ||||||
|         for (i = 0; i < nbox; i++, pbox++) { |         for (i = 0; i < nbox; i++, pbox++) { | ||||||
|             rects[i].x = pbox->x1 - pDraw->x; |             rects[i].x = pbox->x1 - pDraw->x; | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue