From a222349c438ca7108935df461fef6030478f3048 Mon Sep 17 00:00:00 2001 From: "Enrico Weigelt, metux IT consult" Date: Mon, 24 Feb 2025 12:15:01 +0100 Subject: [PATCH] xi: 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 --- Xi/getprop.c | 2 +- Xi/xiproperty.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Xi/getprop.c b/Xi/getprop.c index 5ef20373f..7249266bc 100644 --- a/Xi/getprop.c +++ b/Xi/getprop.c @@ -116,7 +116,7 @@ ProcXGetDeviceDontPropagateList(ClientPtr client) ClassFromMask(NULL, others->dontPropagateMask[i], i, &count, COUNT); if (count) { rep.count = count; - buf = xallocarray(rep.count, sizeof(XEventClass)); + buf = calloc(rep.count, sizeof(XEventClass)); rep.length = bytes_to_int32(rep.count * sizeof(XEventClass)); tbuf = buf; diff --git a/Xi/xiproperty.c b/Xi/xiproperty.c index 55c52addb..2691a8935 100644 --- a/Xi/xiproperty.c +++ b/Xi/xiproperty.c @@ -222,7 +222,7 @@ list_atoms(DeviceIntPtr dev, int *natoms, Atom **atoms_return) if (nprops) { Atom *a; - atoms = xallocarray(nprops, sizeof(Atom)); + atoms = calloc(nprops, sizeof(Atom)); if (!atoms) return BadAlloc; a = atoms; @@ -723,7 +723,7 @@ XIChangeDeviceProperty(DeviceIntPtr dev, Atom property, Atom type, if (mode == PropModeReplace || len > 0) { void *new_data = NULL, *old_data = NULL; - new_value.data = xallocarray(total_len, size_in_bytes); + new_value.data = calloc(total_len, size_in_bytes); if (!new_value.data && total_len && size_in_bytes) { if (add) XIDestroyDeviceProperty(prop);