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
e23e409597
commit
ba4fb2588e
|
@ -192,7 +192,7 @@ InitAtoms(void)
|
||||||
{
|
{
|
||||||
FreeAllAtoms();
|
FreeAllAtoms();
|
||||||
tableLength = InitialTableSize;
|
tableLength = InitialTableSize;
|
||||||
nodeTable = xallocarray(InitialTableSize, sizeof(NodePtr));
|
nodeTable = calloc(InitialTableSize, sizeof(NodePtr));
|
||||||
if (!nodeTable)
|
if (!nodeTable)
|
||||||
FatalError("creating atom table");
|
FatalError("creating atom table");
|
||||||
nodeTable[None] = NULL;
|
nodeTable[None] = NULL;
|
||||||
|
|
|
@ -308,7 +308,7 @@ dixCreateColormap(Colormap mid, ScreenPtr pScreen, VisualPtr pVisual,
|
||||||
for (pent = &pmap->red[size - 1]; pent >= pmap->red; pent--)
|
for (pent = &pmap->red[size - 1]; pent >= pmap->red; pent--)
|
||||||
pent->refcnt = AllocPrivate;
|
pent->refcnt = AllocPrivate;
|
||||||
pmap->freeRed = 0;
|
pmap->freeRed = 0;
|
||||||
ppix = xallocarray(size, sizeof(Pixel));
|
ppix = calloc(size, sizeof(Pixel));
|
||||||
if (!ppix) {
|
if (!ppix) {
|
||||||
free(pmap);
|
free(pmap);
|
||||||
return BadAlloc;
|
return BadAlloc;
|
||||||
|
@ -349,7 +349,7 @@ dixCreateColormap(Colormap mid, ScreenPtr pScreen, VisualPtr pVisual,
|
||||||
for (pent = &pmap->green[size - 1]; pent >= pmap->green; pent--)
|
for (pent = &pmap->green[size - 1]; pent >= pmap->green; pent--)
|
||||||
pent->refcnt = AllocPrivate;
|
pent->refcnt = AllocPrivate;
|
||||||
pmap->freeGreen = 0;
|
pmap->freeGreen = 0;
|
||||||
ppix = xallocarray(size, sizeof(Pixel));
|
ppix = calloc(size, sizeof(Pixel));
|
||||||
if (!ppix) {
|
if (!ppix) {
|
||||||
free(pmap->clientPixelsRed[clientIndex]);
|
free(pmap->clientPixelsRed[clientIndex]);
|
||||||
free(pmap);
|
free(pmap);
|
||||||
|
@ -364,7 +364,7 @@ dixCreateColormap(Colormap mid, ScreenPtr pScreen, VisualPtr pVisual,
|
||||||
for (pent = &pmap->blue[size - 1]; pent >= pmap->blue; pent--)
|
for (pent = &pmap->blue[size - 1]; pent >= pmap->blue; pent--)
|
||||||
pent->refcnt = AllocPrivate;
|
pent->refcnt = AllocPrivate;
|
||||||
pmap->freeBlue = 0;
|
pmap->freeBlue = 0;
|
||||||
ppix = xallocarray(size, sizeof(Pixel));
|
ppix = calloc(size, sizeof(Pixel));
|
||||||
if (!ppix) {
|
if (!ppix) {
|
||||||
free(pmap->clientPixelsGreen[clientIndex]);
|
free(pmap->clientPixelsGreen[clientIndex]);
|
||||||
free(pmap->clientPixelsRed[clientIndex]);
|
free(pmap->clientPixelsRed[clientIndex]);
|
||||||
|
@ -714,7 +714,7 @@ doUpdateColors(ColormapPtr pmap)
|
||||||
|
|
||||||
pVisual = pmap->pVisual;
|
pVisual = pmap->pVisual;
|
||||||
size = pVisual->ColormapEntries;
|
size = pVisual->ColormapEntries;
|
||||||
defs = xallocarray(size, sizeof(xColorItem));
|
defs = calloc(size, sizeof(xColorItem));
|
||||||
if (!defs)
|
if (!defs)
|
||||||
return;
|
return;
|
||||||
n = 0;
|
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++)
|
for (p = pixels; p < pixels + c; p++)
|
||||||
*p = 0;
|
*p = 0;
|
||||||
|
|
||||||
ppixRed = xallocarray(npixR, sizeof(Pixel));
|
ppixRed = calloc(npixR, sizeof(Pixel));
|
||||||
ppixGreen = xallocarray(npixG, sizeof(Pixel));
|
ppixGreen = calloc(npixG, sizeof(Pixel));
|
||||||
ppixBlue = xallocarray(npixB, sizeof(Pixel));
|
ppixBlue = calloc(npixB, sizeof(Pixel));
|
||||||
if (!ppixRed || !ppixGreen || !ppixBlue) {
|
if (!ppixRed || !ppixGreen || !ppixBlue) {
|
||||||
free(ppixBlue);
|
free(ppixBlue);
|
||||||
free(ppixGreen);
|
free(ppixGreen);
|
||||||
|
@ -1760,7 +1760,7 @@ AllocPseudo(int client, ColormapPtr pmap, int c, int r, Bool contig,
|
||||||
npix = c << r;
|
npix = c << r;
|
||||||
if ((r >= 32) || (npix > pmap->freeRed) || (npix < c))
|
if ((r >= 32) || (npix > pmap->freeRed) || (npix < c))
|
||||||
return BadAlloc;
|
return BadAlloc;
|
||||||
if (!(ppixTemp = xallocarray(npix, sizeof(Pixel))))
|
if (!(ppixTemp = calloc(npix, sizeof(Pixel))))
|
||||||
return BadAlloc;
|
return BadAlloc;
|
||||||
ok = AllocCP(pmap, pmap->red, c, r, contig, ppixTemp, pmask);
|
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);
|
npixClientNew = c << (r + g + b);
|
||||||
npixShared = (c << r) + (c << g) + (c << b);
|
npixShared = (c << r) + (c << g) + (c << b);
|
||||||
psharedList = xallocarray(npixShared, sizeof(SHAREDCOLOR *));
|
psharedList = calloc(npixShared, sizeof(SHAREDCOLOR *));
|
||||||
if (!psharedList)
|
if (!psharedList)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
ppshared = psharedList;
|
ppshared = psharedList;
|
||||||
|
@ -2481,7 +2481,7 @@ IsMapInstalled(Colormap map, WindowPtr pWin)
|
||||||
Colormap *pmaps;
|
Colormap *pmaps;
|
||||||
int imap, nummaps, found;
|
int imap, nummaps, found;
|
||||||
|
|
||||||
pmaps = xallocarray(pWin->drawable.pScreen->maxInstalledCmaps,
|
pmaps = calloc(pWin->drawable.pScreen->maxInstalledCmaps,
|
||||||
sizeof(Colormap));
|
sizeof(Colormap));
|
||||||
if (!pmaps)
|
if (!pmaps)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
|
@ -1549,8 +1549,8 @@ InitStringFeedbackClassDeviceStruct(DeviceIntPtr dev,
|
||||||
feedc->ctrl.num_symbols_displayed = 0;
|
feedc->ctrl.num_symbols_displayed = 0;
|
||||||
feedc->ctrl.max_symbols = max_symbols;
|
feedc->ctrl.max_symbols = max_symbols;
|
||||||
feedc->ctrl.symbols_supported =
|
feedc->ctrl.symbols_supported =
|
||||||
xallocarray(num_symbols_supported, sizeof(KeySym));
|
calloc(num_symbols_supported, sizeof(KeySym));
|
||||||
feedc->ctrl.symbols_displayed = xallocarray(max_symbols, sizeof(KeySym));
|
feedc->ctrl.symbols_displayed = calloc(max_symbols, sizeof(KeySym));
|
||||||
if (!feedc->ctrl.symbols_supported || !feedc->ctrl.symbols_displayed) {
|
if (!feedc->ctrl.symbols_supported || !feedc->ctrl.symbols_displayed) {
|
||||||
free(feedc->ctrl.symbols_supported);
|
free(feedc->ctrl.symbols_supported);
|
||||||
free(feedc->ctrl.symbols_displayed);
|
free(feedc->ctrl.symbols_displayed);
|
||||||
|
|
|
@ -1041,7 +1041,7 @@ ProcQueryTree(ClientPtr client)
|
||||||
if (numChildren) {
|
if (numChildren) {
|
||||||
int curChild = 0;
|
int curChild = 0;
|
||||||
|
|
||||||
childIDs = xallocarray(numChildren, sizeof(Window));
|
childIDs = calloc(numChildren, sizeof(Window));
|
||||||
if (!childIDs)
|
if (!childIDs)
|
||||||
return BadAlloc;
|
return BadAlloc;
|
||||||
for (pChild = pWin->lastChild; pChild != pHead;
|
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
|
* copy the current FPE list, so that if it gets changed by another client
|
||||||
* while we're blocking, the request still appears atomic
|
* 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) {
|
if (!c->fpe_list) {
|
||||||
free((void *) c->fontname);
|
free((void *) c->fontname);
|
||||||
free(c);
|
free(c);
|
||||||
|
@ -820,7 +820,7 @@ ListFonts(ClientPtr client, unsigned char *pattern, unsigned length,
|
||||||
|
|
||||||
if (!(c = calloc(1, sizeof *c)))
|
if (!(c = calloc(1, sizeof *c)))
|
||||||
return BadAlloc;
|
return BadAlloc;
|
||||||
c->fpe_list = xallocarray(num_fpes, sizeof(FontPathElementPtr));
|
c->fpe_list = calloc(num_fpes, sizeof(FontPathElementPtr));
|
||||||
if (!c->fpe_list) {
|
if (!c->fpe_list) {
|
||||||
free(c);
|
free(c);
|
||||||
return BadAlloc;
|
return BadAlloc;
|
||||||
|
@ -1070,7 +1070,7 @@ StartListFontsWithInfo(ClientPtr client, int length, unsigned char *pattern,
|
||||||
|
|
||||||
if (!(c = calloc(1, sizeof *c)))
|
if (!(c = calloc(1, sizeof *c)))
|
||||||
goto badAlloc;
|
goto badAlloc;
|
||||||
c->fpe_list = xallocarray(num_fpes, sizeof(FontPathElementPtr));
|
c->fpe_list = calloc(num_fpes, sizeof(FontPathElementPtr));
|
||||||
if (!c->fpe_list) {
|
if (!c->fpe_list) {
|
||||||
free(c);
|
free(c);
|
||||||
goto badAlloc;
|
goto badAlloc;
|
||||||
|
@ -1439,7 +1439,7 @@ doImageText(ClientPtr client, ITclosurePtr c)
|
||||||
*new_closure = *c;
|
*new_closure = *c;
|
||||||
c = new_closure;
|
c = new_closure;
|
||||||
|
|
||||||
data = xallocarray(c->nChars, itemSize);
|
data = calloc(c->nChars, itemSize);
|
||||||
if (!data) {
|
if (!data) {
|
||||||
free(c);
|
free(c);
|
||||||
c = old_closure;
|
c = old_closure;
|
||||||
|
@ -1595,7 +1595,7 @@ SetFontPathElements(int npaths, unsigned char *paths, int *bad, Bool persist)
|
||||||
unsigned char *cp = paths;
|
unsigned char *cp = paths;
|
||||||
FontPathElementPtr fpe = NULL, *fplist;
|
FontPathElementPtr fpe = NULL, *fplist;
|
||||||
|
|
||||||
fplist = xallocarray(npaths, sizeof(FontPathElementPtr));
|
fplist = calloc(npaths, sizeof(FontPathElementPtr));
|
||||||
if (!fplist) {
|
if (!fplist) {
|
||||||
*bad = 0;
|
*bad = 0;
|
||||||
return BadAlloc;
|
return BadAlloc;
|
||||||
|
|
|
@ -601,10 +601,10 @@ DeletePassiveGrabFromList(GrabPtr pMinuendGrab)
|
||||||
i++;
|
i++;
|
||||||
if (!i)
|
if (!i)
|
||||||
return TRUE;
|
return TRUE;
|
||||||
deletes = xallocarray(i, sizeof(GrabPtr));
|
deletes = calloc(i, sizeof(GrabPtr));
|
||||||
adds = xallocarray(i, sizeof(GrabPtr));
|
adds = calloc(i, sizeof(GrabPtr));
|
||||||
updates = xallocarray(i, sizeof(Mask **));
|
updates = calloc(i, sizeof(Mask **));
|
||||||
details = xallocarray(i, sizeof(Mask *));
|
details = calloc(i, sizeof(Mask *));
|
||||||
if (!deletes || !adds || !updates || !details) {
|
if (!deletes || !adds || !updates || !details) {
|
||||||
free(details);
|
free(details);
|
||||||
free(updates);
|
free(updates);
|
||||||
|
|
|
@ -152,8 +152,8 @@ ProcRotateProperties(ClientPtr client)
|
||||||
return rc;
|
return rc;
|
||||||
|
|
||||||
atoms = (Atom *) &stuff[1];
|
atoms = (Atom *) &stuff[1];
|
||||||
props = xallocarray(stuff->nAtoms, sizeof(PropertyPtr));
|
props = calloc(stuff->nAtoms, sizeof(PropertyPtr));
|
||||||
saved = xallocarray(stuff->nAtoms, sizeof(PropertyRec));
|
saved = calloc(stuff->nAtoms, sizeof(PropertyRec));
|
||||||
if (!props || !saved) {
|
if (!props || !saved) {
|
||||||
rc = BadAlloc;
|
rc = BadAlloc;
|
||||||
goto out;
|
goto out;
|
||||||
|
@ -591,7 +591,7 @@ ProcListProperties(ClientPtr client)
|
||||||
numProps++;
|
numProps++;
|
||||||
|
|
||||||
if (numProps) {
|
if (numProps) {
|
||||||
pAtoms = xallocarray(numProps, sizeof(Atom));
|
pAtoms = calloc(numProps, sizeof(Atom));
|
||||||
if (!pAtoms)
|
if (!pAtoms)
|
||||||
return BadAlloc;
|
return BadAlloc;
|
||||||
|
|
||||||
|
|
|
@ -862,10 +862,10 @@ RebuildTable(int client)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
j = 2 * clientTable[client].buckets;
|
j = 2 * clientTable[client].buckets;
|
||||||
tails = xallocarray(j, sizeof(ResourcePtr *));
|
tails = calloc(j, sizeof(ResourcePtr *));
|
||||||
if (!tails)
|
if (!tails)
|
||||||
return;
|
return;
|
||||||
resources = xallocarray(j, sizeof(ResourcePtr));
|
resources = calloc(j, sizeof(ResourcePtr));
|
||||||
if (!resources) {
|
if (!resources) {
|
||||||
free(tails);
|
free(tails);
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Reference in New Issue