[PATCH 11/17] Convert exa & fb to new *allocarray functions

Alan Coopersmith alan.coopersmith at oracle.com
Tue Mar 31 17:50:24 PDT 2015


Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
---
 exa/exa_accel.c           |    8 ++++----
 exa/exa_glyphs.c          |    4 ++--
 exa/exa_migration_mixed.c |    4 ++--
 fb/fbcopy.c               |    2 +-
 fb/fbpict.c               |    2 +-
 5 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/exa/exa_accel.c b/exa/exa_accel.c
index 5aa7d10..e1c51e3 100644
--- a/exa/exa_accel.c
+++ b/exa/exa_accel.c
@@ -386,7 +386,7 @@ exaHWCopyNtoN(DrawablePtr pSrcDrawable,
     exaGetDrawableDeltas(pSrcDrawable, pSrcPixmap, &src_off_x, &src_off_y);
     exaGetDrawableDeltas(pDstDrawable, pDstPixmap, &dst_off_x, &dst_off_y);
 
-    rects = malloc(nbox * sizeof(xRectangle));
+    rects = xallocarray(nbox, sizeof(xRectangle));
 
     if (rects) {
         int i;
@@ -626,7 +626,7 @@ exaPolyPoint(DrawablePtr pDrawable, GCPtr pGC, int mode, int npt,
         return;
     }
 
-    prect = malloc(sizeof(xRectangle) * npt);
+    prect = xallocarray(npt, sizeof(xRectangle));
     for (i = 0; i < npt; i++) {
         prect[i].x = ppt[i].x;
         prect[i].y = ppt[i].y;
@@ -667,7 +667,7 @@ exaPolylines(DrawablePtr pDrawable, GCPtr pGC, int mode, int npt,
         return;
     }
 
-    prect = malloc(sizeof(xRectangle) * (npt - 1));
+    prect = xallocarray(npt -1, sizeof(xRectangle));
     x1 = ppt[0].x;
     y1 = ppt[0].y;
     /* If we have any non-horizontal/vertical, fall back. */
@@ -738,7 +738,7 @@ exaPolySegment(DrawablePtr pDrawable, GCPtr pGC, int nseg, xSegment * pSeg)
         }
     }
 
-    prect = malloc(sizeof(xRectangle) * nseg);
+    prect = xallocarray(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 41f3694..cf21ea9 100644
--- a/exa/exa_glyphs.c
+++ b/exa/exa_glyphs.c
@@ -211,8 +211,8 @@ exaRealizeGlyphCaches(ScreenPtr pScreen, unsigned int format)
 
         cache->picture = pPicture;
         cache->picture->refcnt++;
-        cache->hashEntries = malloc(sizeof(int) * cache->hashSize);
-        cache->glyphs = malloc(sizeof(ExaCachedGlyphRec) * cache->size);
+        cache->hashEntries = xallocarray(cache->hashSize, sizeof(int));
+        cache->glyphs = xallocarray(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 cf66327..7d3fca7 100644
--- a/exa/exa_migration_mixed.c
+++ b/exa/exa_migration_mixed.c
@@ -205,8 +205,8 @@ exaPrepareAccessReg_mixed(PixmapPtr pPixmap, int index, RegionPtr pReg)
 
         /* Do we need to allocate our system buffer? */
         if (!pExaPixmap->sys_ptr) {
-            pExaPixmap->sys_ptr = malloc(pExaPixmap->sys_pitch *
-                                         pPixmap->drawable.height);
+            pExaPixmap->sys_ptr = xallocarray(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);
diff --git a/fb/fbcopy.c b/fb/fbcopy.c
index 5bbabc3..6af10cc 100644
--- a/fb/fbcopy.c
+++ b/fb/fbcopy.c
@@ -194,7 +194,7 @@ fbCopyNto1(DrawablePtr pSrcDrawable,
             height = pbox->y2 - pbox->y1;
 
             tmpStride = ((width + FB_STIP_MASK) >> FB_STIP_SHIFT);
-            tmp = malloc(tmpStride * height * sizeof(FbStip));
+            tmp = xallocarray(tmpStride * height, sizeof(FbStip));
             if (!tmp)
                 return;
 
diff --git a/fb/fbpict.c b/fb/fbpict.c
index c8378ad..cc457c6 100644
--- a/fb/fbpict.c
+++ b/fb/fbpict.c
@@ -124,7 +124,7 @@ fbGlyphs(CARD8 op,
     pixman_glyph_cache_freeze (glyphCache);
 
     if (n_glyphs > N_STACK_GLYPHS) {
-	if (!(pglyphs = malloc (n_glyphs * sizeof (pixman_glyph_t))))
+	if (!(pglyphs = xallocarray (n_glyphs, sizeof (pixman_glyph_t))))
 	    goto out;
     }
 
-- 
1.7.9.2



More information about the xorg-devel mailing list