From 349ba2c3f9e680512de95d3813da071d3c666feb 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 54b8131ec..4e23c100e 100644 --- a/Xi/getprop.c +++ b/Xi/getprop.c @@ -117,7 +117,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 8db6b03d1..bf3b82dd0 100644 --- a/Xi/xiproperty.c +++ b/Xi/xiproperty.c @@ -221,7 +221,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; @@ -724,7 +724,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);