From 34d42a47df2eb8b3037fb742c14458debc62709a Mon Sep 17 00:00:00 2001 From: "Enrico Weigelt, metux IT consult" Date: Mon, 24 Feb 2025 12:15:01 +0100 Subject: [PATCH] (1823) glamor: 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 --- glamor/glamor_compositerects.c | 2 +- glamor/glamor_gradient.c | 8 ++++---- glamor/glamor_prepare.c | 4 ++-- glamor/glamor_utils.c | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/glamor/glamor_compositerects.c b/glamor/glamor_compositerects.c index f245cf69a..dfd950d23 100644 --- a/glamor/glamor_compositerects.c +++ b/glamor/glamor_compositerects.c @@ -58,7 +58,7 @@ _pixman_region_init_clipped_rectangles(pixman_region16_t * region, unsigned int i, j; if (num_rects > ARRAY_SIZE(stack_boxes)) { - boxes = xallocarray(num_rects, sizeof(pixman_box16_t)); + boxes = calloc(num_rects, sizeof(pixman_box16_t)); if (boxes == NULL) return FALSE; } diff --git a/glamor/glamor_gradient.c b/glamor/glamor_gradient.c index fb41bddf3..49777bdab 100644 --- a/glamor/glamor_gradient.c +++ b/glamor/glamor_gradient.c @@ -990,13 +990,13 @@ glamor_generate_radial_gradient_picture(ScreenPtr screen, /* Set all the stops and colors to shader. */ if (stops_count > RADIAL_SMALL_STOPS) { - stop_colors = xallocarray(stops_count, 4 * sizeof(float)); + stop_colors = calloc(stops_count, 4 * sizeof(float)); if (stop_colors == NULL) { ErrorF("Failed to allocate stop_colors memory.\n"); goto GRADIENT_FAIL; } - n_stops = xallocarray(stops_count, sizeof(float)); + n_stops = calloc(stops_count, sizeof(float)); if (n_stops == NULL) { ErrorF("Failed to allocate n_stops memory.\n"); goto GRADIENT_FAIL; @@ -1328,13 +1328,13 @@ glamor_generate_linear_gradient_picture(ScreenPtr screen, /* Set all the stops and colors to shader. */ if (stops_count > LINEAR_SMALL_STOPS) { - stop_colors = xallocarray(stops_count, 4 * sizeof(float)); + stop_colors = calloc(stops_count, 4 * sizeof(float)); if (stop_colors == NULL) { ErrorF("Failed to allocate stop_colors memory.\n"); goto GRADIENT_FAIL; } - n_stops = xallocarray(stops_count, sizeof(float)); + n_stops = calloc(stops_count, sizeof(float)); if (n_stops == NULL) { ErrorF("Failed to allocate n_stops memory.\n"); goto GRADIENT_FAIL; diff --git a/glamor/glamor_prepare.c b/glamor/glamor_prepare.c index 8112cbcf4..b186c999a 100644 --- a/glamor/glamor_prepare.c +++ b/glamor/glamor_prepare.c @@ -123,8 +123,8 @@ glamor_prep_drawable_box(DrawablePtr drawable, glamor_access_t access, BoxPtr bo } if (!priv->pbo) { - pixmap->devPrivate.ptr = xallocarray(pixmap->devKind, - pixmap->drawable.height); + pixmap->devPrivate.ptr = calloc(pixmap->devKind, + pixmap->drawable.height); if (!pixmap->devPrivate.ptr) return FALSE; } diff --git a/glamor/glamor_utils.c b/glamor/glamor_utils.c index 23445137e..ec32aa229 100644 --- a/glamor/glamor_utils.c +++ b/glamor/glamor_utils.c @@ -31,7 +31,7 @@ glamor_solid_boxes(DrawablePtr drawable, xRectangle *rect; int n; - rect = xallocarray(nbox, sizeof(xRectangle)); + rect = calloc(nbox, sizeof(xRectangle)); if (!rect) return; for (n = 0; n < nbox; n++) {