dix: 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
							
								
									1f4c810baa
								
							
						
					
					
						commit
						6dac1cd970
					
				| 
						 | 
				
			
			@ -199,7 +199,7 @@ InitAtoms(void)
 | 
			
		|||
{
 | 
			
		||||
    FreeAllAtoms();
 | 
			
		||||
    tableLength = InitialTableSize;
 | 
			
		||||
    nodeTable = xallocarray(InitialTableSize, sizeof(NodePtr));
 | 
			
		||||
    nodeTable = calloc(InitialTableSize, sizeof(NodePtr));
 | 
			
		||||
    if (!nodeTable)
 | 
			
		||||
        AtomError();
 | 
			
		||||
    nodeTable[None] = NULL;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -308,7 +308,7 @@ CreateColormap(Colormap mid, ScreenPtr pScreen, VisualPtr pVisual,
 | 
			
		|||
        for (pent = &pmap->red[size - 1]; pent >= pmap->red; pent--)
 | 
			
		||||
            pent->refcnt = AllocPrivate;
 | 
			
		||||
        pmap->freeRed = 0;
 | 
			
		||||
        ppix = xallocarray(size, sizeof(Pixel));
 | 
			
		||||
        ppix = calloc(size, sizeof(Pixel));
 | 
			
		||||
        if (!ppix) {
 | 
			
		||||
            free(pmap);
 | 
			
		||||
            return BadAlloc;
 | 
			
		||||
| 
						 | 
				
			
			@ -349,7 +349,7 @@ CreateColormap(Colormap mid, ScreenPtr pScreen, VisualPtr pVisual,
 | 
			
		|||
            for (pent = &pmap->green[size - 1]; pent >= pmap->green; pent--)
 | 
			
		||||
                pent->refcnt = AllocPrivate;
 | 
			
		||||
            pmap->freeGreen = 0;
 | 
			
		||||
            ppix = xallocarray(size, sizeof(Pixel));
 | 
			
		||||
            ppix = calloc(size, sizeof(Pixel));
 | 
			
		||||
            if (!ppix) {
 | 
			
		||||
                free(pmap->clientPixelsRed[client]);
 | 
			
		||||
                free(pmap);
 | 
			
		||||
| 
						 | 
				
			
			@ -364,7 +364,7 @@ CreateColormap(Colormap mid, ScreenPtr pScreen, VisualPtr pVisual,
 | 
			
		|||
            for (pent = &pmap->blue[size - 1]; pent >= pmap->blue; pent--)
 | 
			
		||||
                pent->refcnt = AllocPrivate;
 | 
			
		||||
            pmap->freeBlue = 0;
 | 
			
		||||
            ppix = xallocarray(size, sizeof(Pixel));
 | 
			
		||||
            ppix = calloc(size, sizeof(Pixel));
 | 
			
		||||
            if (!ppix) {
 | 
			
		||||
                free(pmap->clientPixelsGreen[client]);
 | 
			
		||||
                free(pmap->clientPixelsRed[client]);
 | 
			
		||||
| 
						 | 
				
			
			@ -714,7 +714,7 @@ doUpdateColors(ColormapPtr pmap)
 | 
			
		|||
 | 
			
		||||
    pVisual = pmap->pVisual;
 | 
			
		||||
    size = pVisual->ColormapEntries;
 | 
			
		||||
    defs = xallocarray(size, sizeof(xColorItem));
 | 
			
		||||
    defs = calloc(size, sizeof(xColorItem));
 | 
			
		||||
    if (!defs)
 | 
			
		||||
        return;
 | 
			
		||||
    n = 0;
 | 
			
		||||
| 
						 | 
				
			
			@ -1660,9 +1660,9 @@ AllocDirect(int client, ColormapPtr pmap, int c, int r, int g, int b,
 | 
			
		|||
    for (p = pixels; p < pixels + c; p++)
 | 
			
		||||
        *p = 0;
 | 
			
		||||
 | 
			
		||||
    ppixRed = xallocarray(npixR, sizeof(Pixel));
 | 
			
		||||
    ppixGreen = xallocarray(npixG, sizeof(Pixel));
 | 
			
		||||
    ppixBlue = xallocarray(npixB, sizeof(Pixel));
 | 
			
		||||
    ppixRed = calloc(npixR, sizeof(Pixel));
 | 
			
		||||
    ppixGreen = calloc(npixG, sizeof(Pixel));
 | 
			
		||||
    ppixBlue = calloc(npixB, sizeof(Pixel));
 | 
			
		||||
    if (!ppixRed || !ppixGreen || !ppixBlue) {
 | 
			
		||||
        free(ppixBlue);
 | 
			
		||||
        free(ppixGreen);
 | 
			
		||||
| 
						 | 
				
			
			@ -1760,7 +1760,7 @@ AllocPseudo(int client, ColormapPtr pmap, int c, int r, Bool contig,
 | 
			
		|||
    npix = c << r;
 | 
			
		||||
    if ((r >= 32) || (npix > pmap->freeRed) || (npix < c))
 | 
			
		||||
        return BadAlloc;
 | 
			
		||||
    if (!(ppixTemp = xallocarray(npix, sizeof(Pixel))))
 | 
			
		||||
    if (!(ppixTemp = calloc(npix, sizeof(Pixel))))
 | 
			
		||||
        return BadAlloc;
 | 
			
		||||
    ok = AllocCP(pmap, pmap->red, c, r, contig, ppixTemp, pmask);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -1972,7 +1972,7 @@ AllocShared(ColormapPtr pmap, Pixel * ppix, int c, int r, int g, int b,
 | 
			
		|||
 | 
			
		||||
    npixClientNew = c << (r + g + b);
 | 
			
		||||
    npixShared = (c << r) + (c << g) + (c << b);
 | 
			
		||||
    psharedList = xallocarray(npixShared, sizeof(SHAREDCOLOR *));
 | 
			
		||||
    psharedList = calloc(npixShared, sizeof(SHAREDCOLOR *));
 | 
			
		||||
    if (!psharedList)
 | 
			
		||||
        return FALSE;
 | 
			
		||||
    ppshared = psharedList;
 | 
			
		||||
| 
						 | 
				
			
			@ -2481,7 +2481,7 @@ IsMapInstalled(Colormap map, WindowPtr pWin)
 | 
			
		|||
    Colormap *pmaps;
 | 
			
		||||
    int imap, nummaps, found;
 | 
			
		||||
 | 
			
		||||
    pmaps = xallocarray(pWin->drawable.pScreen->maxInstalledCmaps,
 | 
			
		||||
    pmaps = calloc(pWin->drawable.pScreen->maxInstalledCmaps,
 | 
			
		||||
                   sizeof(Colormap));
 | 
			
		||||
    if (!pmaps)
 | 
			
		||||
        return FALSE;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1554,8 +1554,8 @@ InitStringFeedbackClassDeviceStruct(DeviceIntPtr dev,
 | 
			
		|||
    feedc->ctrl.num_symbols_displayed = 0;
 | 
			
		||||
    feedc->ctrl.max_symbols = max_symbols;
 | 
			
		||||
    feedc->ctrl.symbols_supported =
 | 
			
		||||
        xallocarray(num_symbols_supported, sizeof(KeySym));
 | 
			
		||||
    feedc->ctrl.symbols_displayed = xallocarray(max_symbols, sizeof(KeySym));
 | 
			
		||||
        calloc(num_symbols_supported, sizeof(KeySym));
 | 
			
		||||
    feedc->ctrl.symbols_displayed = calloc(max_symbols, sizeof(KeySym));
 | 
			
		||||
    if (!feedc->ctrl.symbols_supported || !feedc->ctrl.symbols_displayed) {
 | 
			
		||||
        free(feedc->ctrl.symbols_supported);
 | 
			
		||||
        free(feedc->ctrl.symbols_displayed);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1089,7 +1089,7 @@ ProcQueryTree(ClientPtr client)
 | 
			
		|||
    if (numChildren) {
 | 
			
		||||
        int curChild = 0;
 | 
			
		||||
 | 
			
		||||
        childIDs = xallocarray(numChildren, sizeof(Window));
 | 
			
		||||
        childIDs = calloc(numChildren, sizeof(Window));
 | 
			
		||||
        if (!childIDs)
 | 
			
		||||
            return BadAlloc;
 | 
			
		||||
        for (pChild = pWin->lastChild; pChild != pHead;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -426,7 +426,7 @@ OpenFont(ClientPtr client, XID fid, Mask flags, unsigned lenfname,
 | 
			
		|||
     * copy the current FPE list, so that if it gets changed by another client
 | 
			
		||||
     * while we're blocking, the request still appears atomic
 | 
			
		||||
     */
 | 
			
		||||
    c->fpe_list = xallocarray(num_fpes, sizeof(FontPathElementPtr));
 | 
			
		||||
    c->fpe_list = calloc(num_fpes, sizeof(FontPathElementPtr));
 | 
			
		||||
    if (!c->fpe_list) {
 | 
			
		||||
        free((void *) c->fontname);
 | 
			
		||||
        free(c);
 | 
			
		||||
| 
						 | 
				
			
			@ -816,7 +816,7 @@ ListFonts(ClientPtr client, unsigned char *pattern, unsigned length,
 | 
			
		|||
 | 
			
		||||
    if (!(c = malloc(sizeof *c)))
 | 
			
		||||
        return BadAlloc;
 | 
			
		||||
    c->fpe_list = xallocarray(num_fpes, sizeof(FontPathElementPtr));
 | 
			
		||||
    c->fpe_list = calloc(num_fpes, sizeof(FontPathElementPtr));
 | 
			
		||||
    if (!c->fpe_list) {
 | 
			
		||||
        free(c);
 | 
			
		||||
        return BadAlloc;
 | 
			
		||||
| 
						 | 
				
			
			@ -1062,7 +1062,7 @@ StartListFontsWithInfo(ClientPtr client, int length, unsigned char *pattern,
 | 
			
		|||
 | 
			
		||||
    if (!(c = malloc(sizeof *c)))
 | 
			
		||||
        goto badAlloc;
 | 
			
		||||
    c->fpe_list = xallocarray(num_fpes, sizeof(FontPathElementPtr));
 | 
			
		||||
    c->fpe_list = calloc(num_fpes, sizeof(FontPathElementPtr));
 | 
			
		||||
    if (!c->fpe_list) {
 | 
			
		||||
        free(c);
 | 
			
		||||
        goto badAlloc;
 | 
			
		||||
| 
						 | 
				
			
			@ -1428,7 +1428,7 @@ doImageText(ClientPtr client, ITclosurePtr c)
 | 
			
		|||
            *new_closure = *c;
 | 
			
		||||
            c = new_closure;
 | 
			
		||||
 | 
			
		||||
            data = xallocarray(c->nChars, itemSize);
 | 
			
		||||
            data = calloc(c->nChars, itemSize);
 | 
			
		||||
            if (!data) {
 | 
			
		||||
                free(c);
 | 
			
		||||
                c = old_closure;
 | 
			
		||||
| 
						 | 
				
			
			@ -1581,7 +1581,7 @@ SetFontPathElements(int npaths, unsigned char *paths, int *bad, Bool persist)
 | 
			
		|||
    unsigned char *cp = paths;
 | 
			
		||||
    FontPathElementPtr fpe = NULL, *fplist;
 | 
			
		||||
 | 
			
		||||
    fplist = xallocarray(npaths, sizeof(FontPathElementPtr));
 | 
			
		||||
    fplist = calloc(npaths, sizeof(FontPathElementPtr));
 | 
			
		||||
    if (!fplist) {
 | 
			
		||||
        *bad = 0;
 | 
			
		||||
        return BadAlloc;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -599,10 +599,10 @@ DeletePassiveGrabFromList(GrabPtr pMinuendGrab)
 | 
			
		|||
        i++;
 | 
			
		||||
    if (!i)
 | 
			
		||||
        return TRUE;
 | 
			
		||||
    deletes = xallocarray(i, sizeof(GrabPtr));
 | 
			
		||||
    adds = xallocarray(i, sizeof(GrabPtr));
 | 
			
		||||
    updates = xallocarray(i, sizeof(Mask **));
 | 
			
		||||
    details = xallocarray(i, sizeof(Mask *));
 | 
			
		||||
    deletes = calloc(i, sizeof(GrabPtr));
 | 
			
		||||
    adds = calloc(i, sizeof(GrabPtr));
 | 
			
		||||
    updates = calloc(i, sizeof(Mask **));
 | 
			
		||||
    details = calloc(i, sizeof(Mask *));
 | 
			
		||||
    if (!deletes || !adds || !updates || !details) {
 | 
			
		||||
        free(details);
 | 
			
		||||
        free(updates);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -149,8 +149,8 @@ ProcRotateProperties(ClientPtr client)
 | 
			
		|||
        return rc;
 | 
			
		||||
 | 
			
		||||
    atoms = (Atom *) &stuff[1];
 | 
			
		||||
    props = xallocarray(stuff->nAtoms, sizeof(PropertyPtr));
 | 
			
		||||
    saved = xallocarray(stuff->nAtoms, sizeof(PropertyRec));
 | 
			
		||||
    props = calloc(stuff->nAtoms, sizeof(PropertyPtr));
 | 
			
		||||
    saved = calloc(stuff->nAtoms, sizeof(PropertyRec));
 | 
			
		||||
    if (!props || !saved) {
 | 
			
		||||
        rc = BadAlloc;
 | 
			
		||||
        goto out;
 | 
			
		||||
| 
						 | 
				
			
			@ -331,7 +331,7 @@ dixChangeWindowProperty(ClientPtr pClient, WindowPtr pWin, Atom property,
 | 
			
		|||
            /* do nothing */
 | 
			
		||||
        }
 | 
			
		||||
        else if (mode == PropModeAppend) {
 | 
			
		||||
            data = xallocarray(pProp->size + len, sizeInBytes);
 | 
			
		||||
            data = calloc(pProp->size + len, sizeInBytes);
 | 
			
		||||
            if (!data)
 | 
			
		||||
                return BadAlloc;
 | 
			
		||||
            memcpy(data, pProp->data, pProp->size * sizeInBytes);
 | 
			
		||||
| 
						 | 
				
			
			@ -340,7 +340,7 @@ dixChangeWindowProperty(ClientPtr pClient, WindowPtr pWin, Atom property,
 | 
			
		|||
            pProp->size += len;
 | 
			
		||||
        }
 | 
			
		||||
        else if (mode == PropModePrepend) {
 | 
			
		||||
            data = xallocarray(len + pProp->size, sizeInBytes);
 | 
			
		||||
            data = calloc(len + pProp->size, sizeInBytes);
 | 
			
		||||
            if (!data)
 | 
			
		||||
                return BadAlloc;
 | 
			
		||||
            memcpy(data + totalSize, pProp->data, pProp->size * sizeInBytes);
 | 
			
		||||
| 
						 | 
				
			
			@ -592,7 +592,7 @@ ProcListProperties(ClientPtr client)
 | 
			
		|||
        numProps++;
 | 
			
		||||
 | 
			
		||||
    if (numProps) {
 | 
			
		||||
        pAtoms = xallocarray(numProps, sizeof(Atom));
 | 
			
		||||
        pAtoms = calloc(numProps, sizeof(Atom));
 | 
			
		||||
        if (!pAtoms)
 | 
			
		||||
            return BadAlloc;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -852,10 +852,10 @@ RebuildTable(int client)
 | 
			
		|||
     */
 | 
			
		||||
 | 
			
		||||
    j = 2 * clientTable[client].buckets;
 | 
			
		||||
    tails =  xallocarray(j, sizeof(ResourcePtr *));
 | 
			
		||||
    tails =  calloc(j, sizeof(ResourcePtr *));
 | 
			
		||||
    if (!tails)
 | 
			
		||||
        return;
 | 
			
		||||
    resources =  xallocarray(j, sizeof(ResourcePtr));
 | 
			
		||||
    resources =  calloc(j, sizeof(ResourcePtr));
 | 
			
		||||
    if (!resources) {
 | 
			
		||||
        free(tails);
 | 
			
		||||
        return;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue