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:
parent
a51511635c
commit
538bfd4acb
|
@ -170,7 +170,7 @@ RRCrtcNotify(RRCrtcPtr crtc,
|
||||||
newoutputs = reallocarray(crtc->outputs,
|
newoutputs = reallocarray(crtc->outputs,
|
||||||
numOutputs, sizeof(RROutputPtr));
|
numOutputs, sizeof(RROutputPtr));
|
||||||
else
|
else
|
||||||
newoutputs = xallocarray(numOutputs, sizeof(RROutputPtr));
|
newoutputs = calloc(numOutputs, sizeof(RROutputPtr));
|
||||||
if (!newoutputs)
|
if (!newoutputs)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
@ -1059,7 +1059,7 @@ RRCrtcGammaSetSize(RRCrtcPtr crtc, int size)
|
||||||
if (size == crtc->gammaSize)
|
if (size == crtc->gammaSize)
|
||||||
return TRUE;
|
return TRUE;
|
||||||
if (size) {
|
if (size) {
|
||||||
gamma = xallocarray(size, 3 * sizeof(CARD16));
|
gamma = calloc(size, 3 * sizeof(CARD16));
|
||||||
if (!gamma)
|
if (!gamma)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
@ -1295,7 +1295,7 @@ ProcRRSetCrtcConfig(ClientPtr client)
|
||||||
return BadMatch;
|
return BadMatch;
|
||||||
}
|
}
|
||||||
if (numOutputs) {
|
if (numOutputs) {
|
||||||
outputs = xallocarray(numOutputs, sizeof(RROutputPtr));
|
outputs = calloc(numOutputs, sizeof(RROutputPtr));
|
||||||
if (!outputs)
|
if (!outputs)
|
||||||
return BadAlloc;
|
return BadAlloc;
|
||||||
}
|
}
|
||||||
|
|
|
@ -168,7 +168,7 @@ RRModesForScreen(ScreenPtr pScreen, int *num_ret)
|
||||||
RRModePtr *screen_modes;
|
RRModePtr *screen_modes;
|
||||||
int num_screen_modes = 0;
|
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)
|
if (!screen_modes)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
|
|
@ -130,7 +130,7 @@ RROutputSetClones(RROutputPtr output, RROutputPtr * clones, int numClones)
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
if (numClones) {
|
if (numClones) {
|
||||||
newClones = xallocarray(numClones, sizeof(RROutputPtr));
|
newClones = calloc(numClones, sizeof(RROutputPtr));
|
||||||
if (!newClones)
|
if (!newClones)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
@ -163,7 +163,7 @@ RROutputSetModes(RROutputPtr output,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (numModes) {
|
if (numModes) {
|
||||||
newModes = xallocarray(numModes, sizeof(RRModePtr));
|
newModes = calloc(numModes, sizeof(RRModePtr));
|
||||||
if (!newModes)
|
if (!newModes)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
@ -262,7 +262,7 @@ RROutputSetCrtcs(RROutputPtr output, RRCrtcPtr * crtcs, int numCrtcs)
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
if (numCrtcs) {
|
if (numCrtcs) {
|
||||||
newCrtcs = xallocarray(numCrtcs, sizeof(RRCrtcPtr));
|
newCrtcs = calloc(numCrtcs, sizeof(RRCrtcPtr));
|
||||||
if (!newCrtcs)
|
if (!newCrtcs)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
|
@ -207,7 +207,7 @@ RRChangeOutputProperty(RROutputPtr output, Atom property, Atom type,
|
||||||
if (mode == PropModeReplace || len > 0) {
|
if (mode == PropModeReplace || len > 0) {
|
||||||
void *new_data = NULL, *old_data = NULL;
|
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 (!new_value.data && total_len && size_in_bytes) {
|
||||||
if (add)
|
if (add)
|
||||||
RRDestroyOutputProperty(prop);
|
RRDestroyOutputProperty(prop);
|
||||||
|
@ -379,7 +379,7 @@ RRConfigureOutputProperty(RROutputPtr output, Atom property,
|
||||||
return BadMatch;
|
return BadMatch;
|
||||||
}
|
}
|
||||||
|
|
||||||
new_values = xallocarray(num_values, sizeof(INT32));
|
new_values = calloc(num_values, sizeof(INT32));
|
||||||
if (!new_values && num_values) {
|
if (!new_values && num_values) {
|
||||||
if (add)
|
if (add)
|
||||||
RRDestroyOutputProperty(prop);
|
RRDestroyOutputProperty(prop);
|
||||||
|
@ -477,7 +477,7 @@ ProcRRQueryOutputProperty(ClientPtr client)
|
||||||
return BadName;
|
return BadName;
|
||||||
|
|
||||||
if (prop->num_valid) {
|
if (prop->num_valid) {
|
||||||
extra = xallocarray(prop->num_valid, sizeof(INT32));
|
extra = calloc(prop->num_valid, sizeof(INT32));
|
||||||
if (!extra)
|
if (!extra)
|
||||||
return BadAlloc;
|
return BadAlloc;
|
||||||
}
|
}
|
||||||
|
|
|
@ -347,7 +347,7 @@ RRConfigureProviderProperty(RRProviderPtr provider, Atom property,
|
||||||
return BadMatch;
|
return BadMatch;
|
||||||
}
|
}
|
||||||
|
|
||||||
new_values = xallocarray(num_values, sizeof(INT32));
|
new_values = calloc(num_values, sizeof(INT32));
|
||||||
if (!new_values && num_values) {
|
if (!new_values && num_values) {
|
||||||
if (add)
|
if (add)
|
||||||
RRDestroyProviderProperty(prop);
|
RRDestroyProviderProperty(prop);
|
||||||
|
@ -396,7 +396,7 @@ ProcRRListProviderProperties(ClientPtr client)
|
||||||
for (prop = provider->properties; prop; prop = prop->next)
|
for (prop = provider->properties; prop; prop = prop->next)
|
||||||
numProps++;
|
numProps++;
|
||||||
if (numProps)
|
if (numProps)
|
||||||
if (!(pAtoms = xallocarray(numProps, sizeof(Atom))))
|
if (!(pAtoms = calloc(numProps, sizeof(Atom))))
|
||||||
return BadAlloc;
|
return BadAlloc;
|
||||||
|
|
||||||
xRRListProviderPropertiesReply rep = {
|
xRRListProviderPropertiesReply rep = {
|
||||||
|
@ -440,7 +440,7 @@ ProcRRQueryProviderProperty(ClientPtr client)
|
||||||
return BadName;
|
return BadName;
|
||||||
|
|
||||||
if (prop->num_valid) {
|
if (prop->num_valid) {
|
||||||
extra = xallocarray(prop->num_valid, sizeof(INT32));
|
extra = calloc(prop->num_valid, sizeof(INT32));
|
||||||
if (!extra)
|
if (!extra)
|
||||||
return BadAlloc;
|
return BadAlloc;
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,7 +70,7 @@ RRTransformSetFilter(RRTransformPtr dst,
|
||||||
xFixed *new_params;
|
xFixed *new_params;
|
||||||
|
|
||||||
if (nparams) {
|
if (nparams) {
|
||||||
new_params = xallocarray(nparams, sizeof(xFixed));
|
new_params = calloc(nparams, sizeof(xFixed));
|
||||||
if (!new_params)
|
if (!new_params)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
memcpy(new_params, params, nparams * sizeof(xFixed));
|
memcpy(new_params, params, nparams * sizeof(xFixed));
|
||||||
|
|
Loading…
Reference in New Issue