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:
Enrico Weigelt, metux IT consult 2025-02-24 12:15:01 +01:00
parent e23e409597
commit ba4fb2588e
8 changed files with 29 additions and 29 deletions

View File

@ -192,7 +192,7 @@ InitAtoms(void)
{
FreeAllAtoms();
tableLength = InitialTableSize;
nodeTable = xallocarray(InitialTableSize, sizeof(NodePtr));
nodeTable = calloc(InitialTableSize, sizeof(NodePtr));
if (!nodeTable)
FatalError("creating atom table");
nodeTable[None] = NULL;

View File

@ -308,7 +308,7 @@ dixCreateColormap(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 @@ dixCreateColormap(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[clientIndex]);
free(pmap);
@ -364,7 +364,7 @@ dixCreateColormap(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[clientIndex]);
free(pmap->clientPixelsRed[clientIndex]);
@ -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,8 +2481,8 @@ IsMapInstalled(Colormap map, WindowPtr pWin)
Colormap *pmaps;
int imap, nummaps, found;
pmaps = xallocarray(pWin->drawable.pScreen->maxInstalledCmaps,
sizeof(Colormap));
pmaps = calloc(pWin->drawable.pScreen->maxInstalledCmaps,
sizeof(Colormap));
if (!pmaps)
return FALSE;
nummaps = (*pWin->drawable.pScreen->ListInstalledColormaps)

View File

@ -1549,8 +1549,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);

View File

@ -1041,7 +1041,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;

View File

@ -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);
@ -820,7 +820,7 @@ ListFonts(ClientPtr client, unsigned char *pattern, unsigned length,
if (!(c = calloc(1, 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;
@ -1070,7 +1070,7 @@ StartListFontsWithInfo(ClientPtr client, int length, unsigned char *pattern,
if (!(c = calloc(1, 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;
@ -1439,7 +1439,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;
@ -1595,7 +1595,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;

View File

@ -601,10 +601,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);

View File

@ -152,8 +152,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;
@ -591,7 +591,7 @@ ProcListProperties(ClientPtr client)
numProps++;
if (numProps) {
pAtoms = xallocarray(numProps, sizeof(Atom));
pAtoms = calloc(numProps, sizeof(Atom));
if (!pAtoms)
return BadAlloc;

View File

@ -862,10 +862,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;