dbe: 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 eb5ebae908
commit e23e409597
2 changed files with 3 additions and 3 deletions

View File

@ -465,7 +465,7 @@ ProcDbeSwapBuffers(ClientPtr client)
dbeSwapInfo = (xDbeSwapInfo *) &stuff[1]; dbeSwapInfo = (xDbeSwapInfo *) &stuff[1];
/* Allocate array to record swap information. */ /* Allocate array to record swap information. */
swapInfo = xallocarray(nStuff, sizeof(DbeSwapInfoRec)); swapInfo = calloc(nStuff, sizeof(DbeSwapInfoRec));
if (swapInfo == NULL) { if (swapInfo == NULL) {
return BadAlloc; return BadAlloc;
} }
@ -578,7 +578,7 @@ ProcDbeGetVisualInfo(ClientPtr client)
return BadAlloc; return BadAlloc;
/* Make sure any specified drawables are valid. */ /* Make sure any specified drawables are valid. */
if (stuff->n != 0) { if (stuff->n != 0) {
if (!(pDrawables = xallocarray(stuff->n, sizeof(DrawablePtr)))) { if (!(pDrawables = calloc(stuff->n, sizeof(DrawablePtr)))) {
return BadAlloc; return BadAlloc;
} }

View File

@ -85,7 +85,7 @@ miDbeGetVisualInfo(ScreenPtr pScreen, XdbeScreenVisualInfo * pScrVisInfo)
} }
/* Allocate an array of XdbeVisualInfo items. */ /* Allocate an array of XdbeVisualInfo items. */
if (!(visInfo = xallocarray(count, sizeof(XdbeVisualInfo)))) { if (!(visInfo = calloc(count, sizeof(XdbeVisualInfo)))) {
return FALSE; /* memory alloc failure */ return FALSE; /* memory alloc failure */
} }