From 5a003a76630167427dd4a87141027245205bb08b Mon Sep 17 00:00:00 2001 From: "Enrico Weigelt, metux IT consult" Date: Mon, 24 Feb 2025 12:15:01 +0100 Subject: [PATCH] kdrive: 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/kdrive/ephyr/hostx.c | 4 ++-- hw/kdrive/src/kshadow.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/hw/kdrive/ephyr/hostx.c b/hw/kdrive/ephyr/hostx.c index 7fcca5ce0..1fb3b9d7b 100644 --- a/hw/kdrive/ephyr/hostx.c +++ b/hw/kdrive/ephyr/hostx.c @@ -939,7 +939,7 @@ hostx_screen_init(KdScreenInfo *screen, scrpriv->ximg->byte_order = IMAGE_BYTE_ORDER; scrpriv->ximg->data = - xallocarray(scrpriv->ximg->stride, buffer_height); + calloc(scrpriv->ximg->stride, buffer_height); } if (!HostX.size_set_from_configure) @@ -1008,7 +1008,7 @@ hostx_screen_init(KdScreenInfo *screen, *bits_per_pixel = scrpriv->server_depth; EPHYR_DBG("server bpp %i", bytes_per_pixel); - scrpriv->fb_data = xallocarray (stride, buffer_height); + scrpriv->fb_data = calloc(stride, buffer_height); return scrpriv->fb_data; } } diff --git a/hw/kdrive/src/kshadow.c b/hw/kdrive/src/kshadow.c index 292a03321..ef0dd99dd 100644 --- a/hw/kdrive/src/kshadow.c +++ b/hw/kdrive/src/kshadow.c @@ -34,7 +34,7 @@ KdShadowFbAlloc(KdScreenInfo * screen, Bool rotate) /* use fb computation for width */ paddedWidth = ((width * bpp + FB_MASK) >> FB_SHIFT) * sizeof(FbBits); - buf = xallocarray(paddedWidth, height); + buf = calloc(paddedWidth, height); if (!buf) return FALSE; if (screen->fb.shadow)