randr: 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 a8f0e2801e
commit f25921f5fb
5 changed files with 10 additions and 10 deletions

View File

@@ -132,7 +132,7 @@ RROutputSetClones(RROutputPtr output, RROutputPtr * clones, int numClones)
RROutputPtr *newClones = NULL;
if (numClones) {
newClones = xallocarray(numClones, sizeof(RROutputPtr));
newClones = calloc(numClones, sizeof(RROutputPtr));
if (!newClones)
return FALSE;
memcpy(newClones, clones, numClones * sizeof(RROutputPtr));
@@ -164,7 +164,7 @@ RROutputSetModes(RROutputPtr output,
RRModePtr *newModes = NULL;
if (numModes) {
newModes = xallocarray(numModes, sizeof(RRModePtr));
newModes = calloc(numModes, sizeof(RRModePtr));
if (!newModes)
return FALSE;
memcpy(newModes, modes, numModes * sizeof(RRModePtr));
@@ -263,7 +263,7 @@ RROutputSetCrtcs(RROutputPtr output, RRCrtcPtr * crtcs, int numCrtcs)
RRCrtcPtr *newCrtcs = NULL;
if (numCrtcs) {
newCrtcs = xallocarray(numCrtcs, sizeof(RRCrtcPtr));
newCrtcs = calloc(numCrtcs, sizeof(RRCrtcPtr));
if (!newCrtcs)
return FALSE;
memcpy(newCrtcs, crtcs, numCrtcs * sizeof(RRCrtcPtr));