[PATCH 13/17] Convert glamor & glx to new *allocarray functions

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


Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
---
 glamor/glamor_compositerects.c |    2 +-
 glamor/glamor_glyphs.c         |    2 +-
 glamor/glamor_gradient.c       |    8 ++++----
 glamor/glamor_pixmap.c         |    4 ++--
 glamor/glamor_prepare.c        |    4 ++--
 glamor/glamor_utils.c          |    2 +-
 glx/single2.c                  |    9 ++++-----
 glx/single2swap.c              |    9 ++++-----
 8 files changed, 19 insertions(+), 21 deletions(-)

diff --git a/glamor/glamor_compositerects.c b/glamor/glamor_compositerects.c
index e188d8a..885a6c0 100644
--- a/glamor/glamor_compositerects.c
+++ b/glamor/glamor_compositerects.c
@@ -57,7 +57,7 @@ _pixman_region_init_clipped_rectangles(pixman_region16_t * region,
     unsigned int i, j;
 
     if (num_rects > ARRAY_SIZE(stack_boxes)) {
-        boxes = malloc(sizeof(pixman_box16_t) * num_rects);
+        boxes = xallocarray(num_rects, sizeof(pixman_box16_t));
         if (boxes == NULL)
             return FALSE;
     }
diff --git a/glamor/glamor_glyphs.c b/glamor/glamor_glyphs.c
index 2cf0c7d..4f3f969 100644
--- a/glamor/glamor_glyphs.c
+++ b/glamor/glamor_glyphs.c
@@ -634,7 +634,7 @@ glyph_new_fixed_list(struct glamor_glyph_list *fixed_list,
     }
     DEBUGF("got %d lists\n", list_cnt);
     if (list_cnt != 0) {
-        fixed_list->list = malloc(list_cnt * sizeof(*cur_list));
+        fixed_list->list = xallocarray(list_cnt, sizeof(*cur_list));
         memcpy(fixed_list->list, *head_list, list_cnt * sizeof(*cur_list));
         fixed_list->list[0].xOff = *head_x;
         fixed_list->list[0].yOff = *head_y;
diff --git a/glamor/glamor_gradient.c b/glamor/glamor_gradient.c
index 8ea645e..d34131d 100644
--- a/glamor/glamor_gradient.c
+++ b/glamor/glamor_gradient.c
@@ -997,13 +997,13 @@ glamor_generate_radial_gradient_picture(ScreenPtr screen,
 
     /* Set all the stops and colors to shader. */
     if (stops_count > RADIAL_SMALL_STOPS) {
-        stop_colors = malloc(4 * stops_count * sizeof(float));
+        stop_colors = xallocarray(stops_count, 4 * sizeof(float));
         if (stop_colors == NULL) {
             ErrorF("Failed to allocate stop_colors memory.\n");
             goto GRADIENT_FAIL;
         }
 
-        n_stops = malloc(stops_count * sizeof(float));
+        n_stops = xallocarray(stops_count, sizeof(float));
         if (n_stops == NULL) {
             ErrorF("Failed to allocate n_stops memory.\n");
             goto GRADIENT_FAIL;
@@ -1338,13 +1338,13 @@ glamor_generate_linear_gradient_picture(ScreenPtr screen,
 
     /* Set all the stops and colors to shader. */
     if (stops_count > LINEAR_SMALL_STOPS) {
-        stop_colors = malloc(4 * stops_count * sizeof(float));
+        stop_colors = xallocarray(stops_count, 4 * sizeof(float));
         if (stop_colors == NULL) {
             ErrorF("Failed to allocate stop_colors memory.\n");
             goto GRADIENT_FAIL;
         }
 
-        n_stops = malloc(stops_count * sizeof(float));
+        n_stops = xallocarray(stops_count, sizeof(float));
         if (n_stops == NULL) {
             ErrorF("Failed to allocate n_stops memory.\n");
             goto GRADIENT_FAIL;
diff --git a/glamor/glamor_pixmap.c b/glamor/glamor_pixmap.c
index 89b4c36..6235747 100644
--- a/glamor/glamor_pixmap.c
+++ b/glamor/glamor_pixmap.c
@@ -775,7 +775,7 @@ _glamor_upload_bits_to_pixmap_texture(PixmapPtr pixmap, GLenum format,
         if (pixmap->drawable.depth == 1)
             stride = (((w * 8 + 7) / 8) + 3) & ~3;
 
-        converted_bits = malloc(h * stride);
+        converted_bits = xallocarray(h, stride);
 
         if (converted_bits == NULL)
             return FALSE;
@@ -966,7 +966,7 @@ glamor_upload_sub_pixmap_to_texture(PixmapPtr pixmap, int x, int y, int w,
         void *sub_bits;
         int i, j;
 
-        sub_bits = malloc(h * stride);
+        sub_bits = xallocarray(h, stride);
         if (sub_bits == NULL)
             return FALSE;
         box.x1 = x;
diff --git a/glamor/glamor_prepare.c b/glamor/glamor_prepare.c
index 83ba7f1..9bfc557 100644
--- a/glamor/glamor_prepare.c
+++ b/glamor/glamor_prepare.c
@@ -91,8 +91,8 @@ glamor_prep_pixmap_box(PixmapPtr pixmap, glamor_access_t access, BoxPtr box)
                          pixmap->devKind * pixmap->drawable.height, NULL,
                          gl_usage);
         } else {
-            pixmap->devPrivate.ptr = malloc(pixmap->devKind *
-                                            pixmap->drawable.height);
+            pixmap->devPrivate.ptr = xallocarray(pixmap->devKind,
+                                                 pixmap->drawable.height);
             if (!pixmap->devPrivate.ptr)
                 return FALSE;
         }
diff --git a/glamor/glamor_utils.c b/glamor/glamor_utils.c
index f068960..1c32cab 100644
--- a/glamor/glamor_utils.c
+++ b/glamor/glamor_utils.c
@@ -31,7 +31,7 @@ glamor_solid_boxes(PixmapPtr pixmap,
     xRectangle *rect;
     int n;
 
-    rect = malloc(nbox * sizeof (xRectangle));
+    rect = xallocarray(nbox, sizeof (xRectangle));
     if (!rect)
         return;
     for (n = 0; n < nbox; n++) {
diff --git a/glx/single2.c b/glx/single2.c
index a6ea614..acc66ac 100644
--- a/glx/single2.c
+++ b/glx/single2.c
@@ -62,9 +62,8 @@ __glXDisp_FeedbackBuffer(__GLXclientState * cl, GLbyte * pc)
     size = *(GLsizei *) (pc + 0);
     type = *(GLenum *) (pc + 4);
     if (cx->feedbackBufSize < size) {
-        cx->feedbackBuf = (GLfloat *) realloc(cx->feedbackBuf,
-                                              (size_t) size
-                                              * __GLX_SIZE_FLOAT32);
+        cx->feedbackBuf = reallocarray(cx->feedbackBuf,
+                                       (size_t) size, __GLX_SIZE_FLOAT32);
         if (!cx->feedbackBuf) {
             cl->client->errorValue = size;
             return BadAlloc;
@@ -94,8 +93,8 @@ __glXDisp_SelectBuffer(__GLXclientState * cl, GLbyte * pc)
     pc += __GLX_SINGLE_HDR_SIZE;
     size = *(GLsizei *) (pc + 0);
     if (cx->selectBufSize < size) {
-        cx->selectBuf = (GLuint *) realloc(cx->selectBuf,
-                                           (size_t) size * __GLX_SIZE_CARD32);
+        cx->selectBuf = reallocarray(cx->selectBuf,
+                                     (size_t) size, __GLX_SIZE_CARD32);
         if (!cx->selectBuf) {
             cl->client->errorValue = size;
             return BadAlloc;
diff --git a/glx/single2swap.c b/glx/single2swap.c
index 5349069..d5bb1c0 100644
--- a/glx/single2swap.c
+++ b/glx/single2swap.c
@@ -63,9 +63,8 @@ __glXDispSwap_FeedbackBuffer(__GLXclientState * cl, GLbyte * pc)
     size = *(GLsizei *) (pc + 0);
     type = *(GLenum *) (pc + 4);
     if (cx->feedbackBufSize < size) {
-        cx->feedbackBuf = (GLfloat *) realloc(cx->feedbackBuf,
-                                              (size_t) size
-                                              * __GLX_SIZE_FLOAT32);
+        cx->feedbackBuf = reallocarray(cx->feedbackBuf,
+                                       (size_t) size, __GLX_SIZE_FLOAT32);
         if (!cx->feedbackBuf) {
             cl->client->errorValue = size;
             return BadAlloc;
@@ -99,8 +98,8 @@ __glXDispSwap_SelectBuffer(__GLXclientState * cl, GLbyte * pc)
     __GLX_SWAP_INT(pc + 0);
     size = *(GLsizei *) (pc + 0);
     if (cx->selectBufSize < size) {
-        cx->selectBuf = (GLuint *) realloc(cx->selectBuf,
-                                           (size_t) size * __GLX_SIZE_CARD32);
+        cx->selectBuf = reallocarray(cx->selectBuf,
+                                     (size_t) size, __GLX_SIZE_CARD32);
         if (!cx->selectBuf) {
             cl->client->errorValue = size;
             return BadAlloc;
-- 
1.7.9.2



More information about the xorg-devel mailing list