From b596d329ec7bb2f4bc03c295ba54853f6e8f6cb1 Mon Sep 17 00:00:00 2001 From: "Enrico Weigelt, metux IT consult" Date: Mon, 24 Feb 2025 12:15:01 +0100 Subject: [PATCH] xwayland: 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 --- hw/xwayland/xwayland-drm-lease.c | 2 +- hw/xwayland/xwayland-output.c | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/hw/xwayland/xwayland-drm-lease.c b/hw/xwayland/xwayland-drm-lease.c index 76f2572a6..cd810c4cc 100644 --- a/hw/xwayland/xwayland-drm-lease.c +++ b/hw/xwayland/xwayland-drm-lease.c @@ -242,7 +242,7 @@ xwl_get_rrmodes_from_connector_id(int drm, int32_t connector_id, int *nmode, int ErrorF("drmModeGetConnector for connector %d failed\n", connector_id); return NULL; } - rrmodes = xallocarray(conn->count_modes, sizeof(RRModePtr)); + rrmodes = calloc(conn->count_modes, sizeof(RRModePtr)); if (!rrmodes) { ErrorF("Failed to allocate connector modes\n"); drmModeFreeConnector(conn); diff --git a/hw/xwayland/xwayland-output.c b/hw/xwayland/xwayland-output.c index 8350279a3..ddcd40ad0 100644 --- a/hw/xwayland/xwayland-output.c +++ b/hw/xwayland/xwayland-output.c @@ -359,7 +359,8 @@ output_get_rr_modes(struct xwl_output *xwl_output, RRModePtr *rr_modes; int i; - rr_modes = xallocarray(ARRAY_SIZE(xwl_output_fake_modes) + 1, sizeof(RRModePtr)); + rr_modes = calloc(ARRAY_SIZE(xwl_output_fake_modes) + 1, + sizeof(RRModePtr)); if (!rr_modes) goto err; @@ -1230,7 +1231,7 @@ xwl_randr_add_modes_fixed(struct xwl_output *xwl_output, RRModePtr mode; int i, nmodes, current; - modes = xallocarray(ARRAY_SIZE(xwl_output_fake_modes) + 1, sizeof(RRModePtr)); + modes = calloc(ARRAY_SIZE(xwl_output_fake_modes) + 1, sizeof(RRModePtr)); if (!modes) { ErrorF("Failed to allocated RandR modes\n"); return FALSE;