From 8e80caa6f79c3434e27c31eb42546a9f04b367a4 Mon Sep 17 00:00:00 2001 From: "Enrico Weigelt, metux IT consult" Date: Mon, 24 Feb 2025 12:15:01 +0100 Subject: [PATCH] exa: 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 --- exa/exa_accel.c | 8 ++++---- exa/exa_glyphs.c | 4 ++-- exa/exa_migration_mixed.c | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/exa/exa_accel.c b/exa/exa_accel.c index efe13db8e..df324c53f 100644 --- a/exa/exa_accel.c +++ b/exa/exa_accel.c @@ -384,7 +384,7 @@ exaHWCopyNtoN(DrawablePtr pSrcDrawable, exaGetDrawableDeltas(pSrcDrawable, pSrcPixmap, &src_off_x, &src_off_y); exaGetDrawableDeltas(pDstDrawable, pDstPixmap, &dst_off_x, &dst_off_y); - rects = xallocarray(nbox, sizeof(xRectangle)); + rects = calloc(nbox, sizeof(xRectangle)); if (rects) { int i; @@ -624,7 +624,7 @@ exaPolyPoint(DrawablePtr pDrawable, GCPtr pGC, int mode, int npt, return; } - prect = xallocarray(npt, sizeof(xRectangle)); + prect = calloc(npt, sizeof(xRectangle)); for (i = 0; i < npt; i++) { prect[i].x = ppt[i].x; prect[i].y = ppt[i].y; @@ -665,7 +665,7 @@ exaPolylines(DrawablePtr pDrawable, GCPtr pGC, int mode, int npt, return; } - prect = xallocarray(npt - 1, sizeof(xRectangle)); + prect = calloc(npt - 1, sizeof(xRectangle)); x1 = ppt[0].x; y1 = ppt[0].y; /* If we have any non-horizontal/vertical, fall back. */ @@ -736,7 +736,7 @@ exaPolySegment(DrawablePtr pDrawable, GCPtr pGC, int nseg, xSegment * pSeg) } } - prect = xallocarray((unsigned int)nseg, sizeof(xRectangle)); + prect = calloc((unsigned int)nseg, sizeof(xRectangle)); for (i = 0; i < nseg; i++) { if (pSeg[i].x1 < pSeg[i].x2) { prect[i].x = pSeg[i].x1; diff --git a/exa/exa_glyphs.c b/exa/exa_glyphs.c index 3ea4a540e..4ec50d452 100644 --- a/exa/exa_glyphs.c +++ b/exa/exa_glyphs.c @@ -209,8 +209,8 @@ exaRealizeGlyphCaches(ScreenPtr pScreen, unsigned int format) cache->picture = pPicture; cache->picture->refcnt++; - cache->hashEntries = xallocarray(cache->hashSize, sizeof(int)); - cache->glyphs = xallocarray(cache->size, sizeof(ExaCachedGlyphRec)); + cache->hashEntries = calloc(cache->hashSize, sizeof(int)); + cache->glyphs = calloc(cache->size, sizeof(ExaCachedGlyphRec)); cache->glyphCount = 0; if (!cache->hashEntries || !cache->glyphs) diff --git a/exa/exa_migration_mixed.c b/exa/exa_migration_mixed.c index 52623e3ca..3449088ea 100644 --- a/exa/exa_migration_mixed.c +++ b/exa/exa_migration_mixed.c @@ -203,8 +203,8 @@ exaPrepareAccessReg_mixed(PixmapPtr pPixmap, int index, RegionPtr pReg) /* Do we need to allocate our system buffer? */ if (!pExaPixmap->sys_ptr) { - pExaPixmap->sys_ptr = xallocarray(pExaPixmap->sys_pitch, - pPixmap->drawable.height); + pExaPixmap->sys_ptr = calloc(pExaPixmap->sys_pitch, + pPixmap->drawable.height); if (!pExaPixmap->sys_ptr) FatalError("EXA: malloc failed for size %d bytes\n", pExaPixmap->sys_pitch * pPixmap->drawable.height);