mi: 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
							
								
									4b0b459ac0
								
							
						
					
					
						commit
						c7fb5c25bc
					
				
							
								
								
									
										16
									
								
								mi/miarc.c
								
								
								
								
							
							
						
						
									
										16
									
								
								mi/miarc.c
								
								
								
								
							| 
						 | 
					@ -1193,9 +1193,9 @@ miFillSppPoly(DrawablePtr dst, GCPtr pgc, int count,    /* number of points */
 | 
				
			||||||
    y = ymax - ymin + 1;
 | 
					    y = ymax - ymin + 1;
 | 
				
			||||||
    if ((count < 3) || (y <= 0))
 | 
					    if ((count < 3) || (y <= 0))
 | 
				
			||||||
        return;
 | 
					        return;
 | 
				
			||||||
    ptsOut = FirstPoint = xallocarray(y, sizeof(DDXPointRec));
 | 
					    ptsOut = FirstPoint = calloc(y, sizeof(DDXPointRec));
 | 
				
			||||||
    width = FirstWidth = xallocarray(y, sizeof(int));
 | 
					    width = FirstWidth = calloc(y, sizeof(int));
 | 
				
			||||||
    Marked = xallocarray(count, sizeof(int));
 | 
					    Marked = calloc(count, sizeof(int));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (!ptsOut || !width || !Marked) {
 | 
					    if (!ptsOut || !width || !Marked) {
 | 
				
			||||||
        free(Marked);
 | 
					        free(Marked);
 | 
				
			||||||
| 
						 | 
					@ -1895,10 +1895,10 @@ miComputeArcs(xArc * parcs, int narcs, GCPtr pGC)
 | 
				
			||||||
    isDoubleDash = (pGC->lineStyle == LineDoubleDash);
 | 
					    isDoubleDash = (pGC->lineStyle == LineDoubleDash);
 | 
				
			||||||
    dashOffset = pGC->dashOffset;
 | 
					    dashOffset = pGC->dashOffset;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    data = xallocarray(narcs, sizeof(struct arcData));
 | 
					    data = calloc(narcs, sizeof(struct arcData));
 | 
				
			||||||
    if (!data)
 | 
					    if (!data)
 | 
				
			||||||
        return NULL;
 | 
					        return NULL;
 | 
				
			||||||
    arcs = xallocarray(isDoubleDash ? 2 : 1, sizeof(*arcs));
 | 
					    arcs = calloc(isDoubleDash ? 2 : 1, sizeof(*arcs));
 | 
				
			||||||
    if (!arcs) {
 | 
					    if (!arcs) {
 | 
				
			||||||
        free(data);
 | 
					        free(data);
 | 
				
			||||||
        return NULL;
 | 
					        return NULL;
 | 
				
			||||||
| 
						 | 
					@ -3086,8 +3086,8 @@ fillSpans(DrawablePtr pDrawable, GCPtr pGC)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (nspans == 0)
 | 
					    if (nspans == 0)
 | 
				
			||||||
        return;
 | 
					        return;
 | 
				
			||||||
    xSpan = xSpans = xallocarray(nspans, sizeof(DDXPointRec));
 | 
					    xSpan = xSpans = calloc(nspans, sizeof(DDXPointRec));
 | 
				
			||||||
    xWidth = xWidths = xallocarray(nspans, sizeof(int));
 | 
					    xWidth = xWidths = calloc(nspans, sizeof(int));
 | 
				
			||||||
    if (xSpans && xWidths) {
 | 
					    if (xSpans && xWidths) {
 | 
				
			||||||
        i = 0;
 | 
					        i = 0;
 | 
				
			||||||
        f = finalSpans;
 | 
					        f = finalSpans;
 | 
				
			||||||
| 
						 | 
					@ -3141,7 +3141,7 @@ realFindSpan(int y)
 | 
				
			||||||
        else
 | 
					        else
 | 
				
			||||||
            change = SPAN_REALLOC;
 | 
					            change = SPAN_REALLOC;
 | 
				
			||||||
        newSize = finalSize + change;
 | 
					        newSize = finalSize + change;
 | 
				
			||||||
        newSpans = xallocarray(newSize, sizeof(struct finalSpan *));
 | 
					        newSpans = calloc(newSize, sizeof(struct finalSpan *));
 | 
				
			||||||
        if (!newSpans)
 | 
					        if (!newSpans)
 | 
				
			||||||
            return NULL;
 | 
					            return NULL;
 | 
				
			||||||
        newMiny = finalMiny;
 | 
					        newMiny = finalMiny;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -465,9 +465,9 @@ miInitVisuals(VisualPtr * visualp, DepthPtr * depthp, int *nvisualp,
 | 
				
			||||||
        ndepth++;
 | 
					        ndepth++;
 | 
				
			||||||
        nvisual += visuals->count;
 | 
					        nvisual += visuals->count;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    depth = xallocarray(ndepth, sizeof(DepthRec));
 | 
					    depth = calloc(ndepth, sizeof(DepthRec));
 | 
				
			||||||
    visual = xallocarray(nvisual, sizeof(VisualRec));
 | 
					    visual = calloc(nvisual, sizeof(VisualRec));
 | 
				
			||||||
    preferredCVCs = xallocarray(ndepth, sizeof(int));
 | 
					    preferredCVCs = calloc(ndepth, sizeof(int));
 | 
				
			||||||
    if (!depth || !visual || !preferredCVCs) {
 | 
					    if (!depth || !visual || !preferredCVCs) {
 | 
				
			||||||
        free(depth);
 | 
					        free(depth);
 | 
				
			||||||
        free(visual);
 | 
					        free(visual);
 | 
				
			||||||
| 
						 | 
					@ -488,7 +488,7 @@ miInitVisuals(VisualPtr * visualp, DepthPtr * depthp, int *nvisualp,
 | 
				
			||||||
        prefp++;
 | 
					        prefp++;
 | 
				
			||||||
        vid = NULL;
 | 
					        vid = NULL;
 | 
				
			||||||
        if (nvtype) {
 | 
					        if (nvtype) {
 | 
				
			||||||
            vid = xallocarray(nvtype, sizeof(VisualID));
 | 
					            vid = calloc(nvtype, sizeof(VisualID));
 | 
				
			||||||
            if (!vid) {
 | 
					            if (!vid) {
 | 
				
			||||||
                free(depth);
 | 
					                free(depth);
 | 
				
			||||||
                free(visual);
 | 
					                free(visual);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -60,7 +60,7 @@ miCopyRegion(DrawablePtr pSrcDrawable,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (nbox > 1) {
 | 
					        if (nbox > 1) {
 | 
				
			||||||
            /* keep ordering in each band, reverse order of bands */
 | 
					            /* keep ordering in each band, reverse order of bands */
 | 
				
			||||||
            pboxNew1 = xallocarray(nbox, sizeof(BoxRec));
 | 
					            pboxNew1 = calloc(nbox, sizeof(BoxRec));
 | 
				
			||||||
            if (!pboxNew1)
 | 
					            if (!pboxNew1)
 | 
				
			||||||
                return;
 | 
					                return;
 | 
				
			||||||
            pboxBase = pboxNext = pbox + nbox - 1;
 | 
					            pboxBase = pboxNext = pbox + nbox - 1;
 | 
				
			||||||
| 
						 | 
					@ -91,7 +91,7 @@ miCopyRegion(DrawablePtr pSrcDrawable,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (nbox > 1) {
 | 
					        if (nbox > 1) {
 | 
				
			||||||
            /* reverse order of rects in each band */
 | 
					            /* reverse order of rects in each band */
 | 
				
			||||||
            pboxNew2 = xallocarray(nbox, sizeof(BoxRec));
 | 
					            pboxNew2 = calloc(nbox, sizeof(BoxRec));
 | 
				
			||||||
            if (!pboxNew2) {
 | 
					            if (!pboxNew2) {
 | 
				
			||||||
                free(pboxNew1);
 | 
					                free(pboxNew1);
 | 
				
			||||||
                return;
 | 
					                return;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -531,7 +531,7 @@ miPaintWindow(WindowPtr pWin, RegionPtr prgn, int what)
 | 
				
			||||||
    regionnumrects = RegionNumRects(prgn);
 | 
					    regionnumrects = RegionNumRects(prgn);
 | 
				
			||||||
    if (regionnumrects == 0)
 | 
					    if (regionnumrects == 0)
 | 
				
			||||||
        return;
 | 
					        return;
 | 
				
			||||||
    prect = xallocarray(regionnumrects, sizeof(xRectangle));
 | 
					    prect = calloc(regionnumrects, sizeof(xRectangle));
 | 
				
			||||||
    if (!prect)
 | 
					    if (!prect)
 | 
				
			||||||
        return;
 | 
					        return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -130,7 +130,7 @@ miPolyGlyphBlt(DrawablePtr pDrawable, GC * pGC, int x, int y, unsigned int nglyp
 | 
				
			||||||
             gcvals);
 | 
					             gcvals);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    nbyLine = BitmapBytePad(width);
 | 
					    nbyLine = BitmapBytePad(width);
 | 
				
			||||||
    pbits = xallocarray(height, nbyLine);
 | 
					    pbits = calloc(height, nbyLine);
 | 
				
			||||||
    if (!pbits) {
 | 
					    if (!pbits) {
 | 
				
			||||||
        dixDestroyPixmap(pPixmap, 0);
 | 
					        dixDestroyPixmap(pPixmap, 0);
 | 
				
			||||||
        FreeScratchGC(pGCtmp);
 | 
					        FreeScratchGC(pGCtmp);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -410,8 +410,8 @@ miFillConvexPoly(DrawablePtr dst, GCPtr pgc, int count, DDXPointPtr ptsIn)
 | 
				
			||||||
    dy = ymax - ymin + 1;
 | 
					    dy = ymax - ymin + 1;
 | 
				
			||||||
    if ((count < 3) || (dy < 0))
 | 
					    if ((count < 3) || (dy < 0))
 | 
				
			||||||
        return TRUE;
 | 
					        return TRUE;
 | 
				
			||||||
    ptsOut = FirstPoint = xallocarray(dy, sizeof(DDXPointRec));
 | 
					    ptsOut = FirstPoint = calloc(dy, sizeof(DDXPointRec));
 | 
				
			||||||
    width = FirstWidth = xallocarray(dy, sizeof(int));
 | 
					    width = FirstWidth = calloc(dy, sizeof(int));
 | 
				
			||||||
    if (!FirstPoint || !FirstWidth) {
 | 
					    if (!FirstPoint || !FirstWidth) {
 | 
				
			||||||
        free(FirstWidth);
 | 
					        free(FirstWidth);
 | 
				
			||||||
        free(FirstPoint);
 | 
					        free(FirstPoint);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -65,7 +65,7 @@ miPolyPoint(DrawablePtr pDrawable, GCPtr pGC, int mode, /* Origin or Previous */
 | 
				
			||||||
    int i;
 | 
					    int i;
 | 
				
			||||||
    xPoint *ppt;
 | 
					    xPoint *ppt;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (!(pwidthInit = xallocarray(npt, sizeof(int))))
 | 
					    if (!(pwidthInit = calloc(npt, sizeof(int))))
 | 
				
			||||||
        return;
 | 
					        return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* make pointlist origin relative */
 | 
					    /* make pointlist origin relative */
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -86,7 +86,7 @@ miPolyRectangle(DrawablePtr pDraw, GCPtr pGC, int nrects, xRectangle *pRects)
 | 
				
			||||||
        offset2 = pGC->lineWidth;
 | 
					        offset2 = pGC->lineWidth;
 | 
				
			||||||
        offset1 = offset2 >> 1;
 | 
					        offset1 = offset2 >> 1;
 | 
				
			||||||
        offset3 = offset2 - offset1;
 | 
					        offset3 = offset2 - offset1;
 | 
				
			||||||
        tmp = xallocarray(ntmp, sizeof(xRectangle));
 | 
					        tmp = calloc(ntmp, sizeof(xRectangle));
 | 
				
			||||||
        if (!tmp)
 | 
					        if (!tmp)
 | 
				
			||||||
            return;
 | 
					            return;
 | 
				
			||||||
        t = tmp;
 | 
					        t = tmp;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -443,8 +443,8 @@ miFillUniqueSpanGroup(DrawablePtr pDraw, GCPtr pGC, SpanGroup * spanGroup)
 | 
				
			||||||
        ylength = spanGroup->ymax - ymin + 1;
 | 
					        ylength = spanGroup->ymax - ymin + 1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        /* Allocate Spans for y buckets */
 | 
					        /* Allocate Spans for y buckets */
 | 
				
			||||||
        yspans = xallocarray(ylength, sizeof(Spans));
 | 
					        yspans = calloc(ylength, sizeof(Spans));
 | 
				
			||||||
        ysizes = xallocarray(ylength, sizeof(int));
 | 
					        ysizes = calloc(ylength, sizeof(int));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (!yspans || !ysizes) {
 | 
					        if (!yspans || !ysizes) {
 | 
				
			||||||
            free(yspans);
 | 
					            free(yspans);
 | 
				
			||||||
| 
						 | 
					@ -511,8 +511,8 @@ miFillUniqueSpanGroup(DrawablePtr pDraw, GCPtr pGC, SpanGroup * spanGroup)
 | 
				
			||||||
        }                       /* for i thorough Spans */
 | 
					        }                       /* for i thorough Spans */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        /* Now sort by x and uniquify each bucket into the final array */
 | 
					        /* Now sort by x and uniquify each bucket into the final array */
 | 
				
			||||||
        points = xallocarray(count, sizeof(DDXPointRec));
 | 
					        points = calloc(count, sizeof(DDXPointRec));
 | 
				
			||||||
        widths = xallocarray(count, sizeof(int));
 | 
					        widths = calloc(count, sizeof(int));
 | 
				
			||||||
        if (!points || !widths) {
 | 
					        if (!points || !widths) {
 | 
				
			||||||
            for (i = 0; i < ylength; i++) {
 | 
					            for (i = 0; i < ylength; i++) {
 | 
				
			||||||
                free(yspans[i].points);
 | 
					                free(yspans[i].points);
 | 
				
			||||||
| 
						 | 
					@ -559,10 +559,10 @@ miFillUniqueSpanGroup(DrawablePtr pDraw, GCPtr pGC, SpanGroup * spanGroup)
 | 
				
			||||||
static Bool
 | 
					static Bool
 | 
				
			||||||
InitSpans(Spans * spans, size_t nspans)
 | 
					InitSpans(Spans * spans, size_t nspans)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    spans->points = xallocarray(nspans, sizeof(*spans->points));
 | 
					    spans->points = calloc(nspans, sizeof(*spans->points));
 | 
				
			||||||
    if (!spans->points)
 | 
					    if (!spans->points)
 | 
				
			||||||
        return FALSE;
 | 
					        return FALSE;
 | 
				
			||||||
    spans->widths = xallocarray(nspans, sizeof(*spans->widths));
 | 
					    spans->widths = calloc(nspans, sizeof(*spans->widths));
 | 
				
			||||||
    if (!spans->widths) {
 | 
					    if (!spans->widths) {
 | 
				
			||||||
        free(spans->points);
 | 
					        free(spans->points);
 | 
				
			||||||
        return FALSE;
 | 
					        return FALSE;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -671,7 +671,7 @@ miZeroPolyArc(DrawablePtr pDraw, GCPtr pGC, int narcs, xArc * parcs)
 | 
				
			||||||
    numPts = maxPts << 2;
 | 
					    numPts = maxPts << 2;
 | 
				
			||||||
    dospans = (pGC->fillStyle != FillSolid);
 | 
					    dospans = (pGC->fillStyle != FillSolid);
 | 
				
			||||||
    if (dospans) {
 | 
					    if (dospans) {
 | 
				
			||||||
        widths = xallocarray(numPts, sizeof(int));
 | 
					        widths = calloc(numPts, sizeof(int));
 | 
				
			||||||
        if (!widths)
 | 
					        if (!widths)
 | 
				
			||||||
            return;
 | 
					            return;
 | 
				
			||||||
        maxw = 0;
 | 
					        maxw = 0;
 | 
				
			||||||
| 
						 | 
					@ -687,7 +687,7 @@ miZeroPolyArc(DrawablePtr pDraw, GCPtr pGC, int narcs, xArc * parcs)
 | 
				
			||||||
                   (unsigned char *) pGC->dash, (int) pGC->numInDashList,
 | 
					                   (unsigned char *) pGC->dash, (int) pGC->numInDashList,
 | 
				
			||||||
                   &dinfo.dashOffsetInit);
 | 
					                   &dinfo.dashOffsetInit);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    points = xallocarray(numPts, sizeof(DDXPointRec));
 | 
					    points = calloc(numPts, sizeof(DDXPointRec));
 | 
				
			||||||
    if (!points) {
 | 
					    if (!points) {
 | 
				
			||||||
        if (dospans) {
 | 
					        if (dospans) {
 | 
				
			||||||
            free(widths);
 | 
					            free(widths);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -148,8 +148,8 @@ miZeroLine(DrawablePtr pDraw, GCPtr pGC, int mode,      /* Origin or Previous */
 | 
				
			||||||
    width = xright - xleft + 1;
 | 
					    width = xright - xleft + 1;
 | 
				
			||||||
    height = ybottom - ytop + 1;
 | 
					    height = ybottom - ytop + 1;
 | 
				
			||||||
    list_len = (height >= width) ? height : width;
 | 
					    list_len = (height >= width) ? height : width;
 | 
				
			||||||
    pspanInit = xallocarray(list_len, sizeof(DDXPointRec));
 | 
					    pspanInit = calloc(list_len, sizeof(DDXPointRec));
 | 
				
			||||||
    pwidthInit = xallocarray(list_len, sizeof(int));
 | 
					    pwidthInit = calloc(list_len, sizeof(int));
 | 
				
			||||||
    if (!pspanInit || !pwidthInit) {
 | 
					    if (!pspanInit || !pwidthInit) {
 | 
				
			||||||
        free(pspanInit);
 | 
					        free(pspanInit);
 | 
				
			||||||
        free(pwidthInit);
 | 
					        free(pwidthInit);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue