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

@ -175,7 +175,7 @@ RRCrtcNotify(RRCrtcPtr crtc,
newoutputs = reallocarray(crtc->outputs,
numOutputs, sizeof(RROutputPtr));
else
newoutputs = xallocarray(numOutputs, sizeof(RROutputPtr));
newoutputs = calloc(numOutputs, sizeof(RROutputPtr));
if (!newoutputs)
return FALSE;
}
@ -1057,7 +1057,7 @@ RRCrtcGammaSetSize(RRCrtcPtr crtc, int size)
if (size == crtc->gammaSize)
return TRUE;
if (size) {
gamma = xallocarray(size, 3 * sizeof(CARD16));
gamma = calloc(size, 3 * sizeof(CARD16));
if (!gamma)
return FALSE;
}
@ -1293,7 +1293,7 @@ ProcRRSetCrtcConfig(ClientPtr client)
return BadMatch;
}
if (numOutputs) {
outputs = xallocarray(numOutputs, sizeof(RROutputPtr));
outputs = calloc(numOutputs, sizeof(RROutputPtr));
if (!outputs)
return BadAlloc;
}

View File

@ -169,7 +169,7 @@ RRModesForScreen(ScreenPtr pScreen, int *num_ret)
RRModePtr *screen_modes;
int num_screen_modes = 0;
screen_modes = xallocarray((num_modes ? num_modes : 1), sizeof(RRModePtr));
screen_modes = calloc((num_modes ? num_modes : 1), sizeof(RRModePtr));
if (!screen_modes)
return NULL;

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));

View File

@ -206,7 +206,7 @@ RRChangeOutputProperty(RROutputPtr output, 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)
RRDestroyOutputProperty(prop);
@ -478,7 +478,7 @@ ProcRRQueryOutputProperty(ClientPtr client)
return BadName;
if (prop->num_valid) {
extra = xallocarray(prop->num_valid, sizeof(INT32));
extra = calloc(prop->num_valid, sizeof(INT32));
if (!extra)
return BadAlloc;
}

View File

@ -65,7 +65,7 @@ RRTransformSetFilter(RRTransformPtr dst,
xFixed *new_params;
if (nparams) {
new_params = xallocarray(nparams, sizeof(xFixed));
new_params = calloc(nparams, sizeof(xFixed));
if (!new_params)
return FALSE;
memcpy(new_params, params, nparams * sizeof(xFixed));