render: 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 953f0a68dc
commit 037a595ad7
5 changed files with 8 additions and 8 deletions

View File

@ -376,7 +376,7 @@ SetPicturePictFilter(PicturePtr pPicture, PictFilterPtr pFilter,
return BadMatch;
if (nparams != pPicture->filter_nparams) {
xFixed *new_params = xallocarray(nparams, sizeof(xFixed));
xFixed *new_params = calloc(nparams, sizeof(xFixed));
if (!new_params && nparams)
return BadAlloc;

View File

@ -249,7 +249,7 @@ miInitIndexed(ScreenPtr pScreen, PictFormatPtr pFormat)
return FALSE;
pFormat->index.nvalues = num;
pFormat->index.pValues = xallocarray(num, sizeof(xIndexValue));
pFormat->index.pValues = calloc(num, sizeof(xIndexValue));
if (!pFormat->index.pValues) {
free(pIndexed);
return FALSE;

View File

@ -508,7 +508,7 @@ miTriStrip(CARD8 op,
int ntri;
ntri = npoints - 2;
tris = xallocarray(ntri, sizeof(xTriangle));
tris = calloc(ntri, sizeof(xTriangle));
if (!tris)
return;
@ -533,7 +533,7 @@ miTriFan(CARD8 op,
int ntri;
ntri = npoints - 2;
tris = xallocarray(ntri, sizeof(xTriangle));
tris = calloc(ntri, sizeof(xTriangle));
if (!tris)
return;

View File

@ -811,7 +811,7 @@ initGradient(SourcePictPtr pGradient, int stopCount,
dpos = stopPoints[i];
}
pGradient->gradient.stops = xallocarray(stopCount, sizeof(PictGradientStop));
pGradient->gradient.stops = calloc(stopCount, sizeof(PictGradientStop));
if (!pGradient->gradient.stops) {
*error = BadAlloc;
return;

View File

@ -1313,14 +1313,14 @@ ProcRenderCompositeGlyphs(ClientPtr client)
if (nglyph <= NLOCALGLYPH)
glyphsBase = glyphsLocal;
else {
glyphsBase = xallocarray(nglyph, sizeof(GlyphPtr));
glyphsBase = calloc(nglyph, sizeof(GlyphPtr));
if (!glyphsBase)
return BadAlloc;
}
if (nlist <= NLOCALDELTA)
listsBase = listsLocal;
else {
listsBase = xallocarray(nlist, sizeof(GlyphListRec));
listsBase = calloc(nlist, sizeof(GlyphListRec));
if (!listsBase) {
rc = BadAlloc;
goto bail;
@ -1799,7 +1799,7 @@ ProcRenderCreateAnimCursor(ClientPtr client)
ncursor =
(client->req_len -
(bytes_to_int32(sizeof(xRenderCreateAnimCursorReq)))) >> 1;
cursors = xallocarray(ncursor, sizeof(CursorPtr) + sizeof(CARD32));
cursors = calloc(ncursor, sizeof(CursorPtr) + sizeof(CARD32));
if (!cursors)
return BadAlloc;
deltas = (CARD32 *) (cursors + ncursor);