From 037a595ad760902e588715d1deb2ac41cd81412b Mon Sep 17 00:00:00 2001 From: "Enrico Weigelt, metux IT consult" Date: Mon, 24 Feb 2025 12:15:01 +0100 Subject: [PATCH] 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 --- render/filter.c | 2 +- render/miindex.c | 2 +- render/mipict.c | 4 ++-- render/picture.c | 2 +- render/render.c | 6 +++--- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/render/filter.c b/render/filter.c index 317a90d36..8a0278819 100644 --- a/render/filter.c +++ b/render/filter.c @@ -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; diff --git a/render/miindex.c b/render/miindex.c index c9d62b916..3fea6fdeb 100644 --- a/render/miindex.c +++ b/render/miindex.c @@ -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; diff --git a/render/mipict.c b/render/mipict.c index 0bc5417c6..2b7332287 100644 --- a/render/mipict.c +++ b/render/mipict.c @@ -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; diff --git a/render/picture.c b/render/picture.c index 513c88ed1..0e5758260 100644 --- a/render/picture.c +++ b/render/picture.c @@ -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; diff --git a/render/render.c b/render/render.c index 686ad806d..4e6389a34 100644 --- a/render/render.c +++ b/render/render.c @@ -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);