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 <info@metux.net>
This commit is contained in:
Enrico Weigelt, metux IT consult 2025-02-24 12:15:01 +01:00
parent d38514d2a2
commit b596d329ec
2 changed files with 4 additions and 3 deletions

View File

@ -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); ErrorF("drmModeGetConnector for connector %d failed\n", connector_id);
return NULL; return NULL;
} }
rrmodes = xallocarray(conn->count_modes, sizeof(RRModePtr)); rrmodes = calloc(conn->count_modes, sizeof(RRModePtr));
if (!rrmodes) { if (!rrmodes) {
ErrorF("Failed to allocate connector modes\n"); ErrorF("Failed to allocate connector modes\n");
drmModeFreeConnector(conn); drmModeFreeConnector(conn);

View File

@ -359,7 +359,8 @@ output_get_rr_modes(struct xwl_output *xwl_output,
RRModePtr *rr_modes; RRModePtr *rr_modes;
int i; 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) if (!rr_modes)
goto err; goto err;
@ -1230,7 +1231,7 @@ xwl_randr_add_modes_fixed(struct xwl_output *xwl_output,
RRModePtr mode; RRModePtr mode;
int i, nmodes, current; 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) { if (!modes) {
ErrorF("Failed to allocated RandR modes\n"); ErrorF("Failed to allocated RandR modes\n");
return FALSE; return FALSE;