xfree86: 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 b32cd8c759
commit 901132b766
13 changed files with 25 additions and 26 deletions

View File

@ -1320,7 +1320,7 @@ ProcXDGAQueryModes(ClientPtr client)
return Success;
}
if (!(mode = xallocarray(num, sizeof(XDGAModeRec))))
if (!(mode = calloc(num, sizeof(XDGAModeRec))))
return BadAlloc;
for (i = 0; i < num; i++)

View File

@ -158,10 +158,10 @@ xf86HandleColormaps(ScreenPtr pScreen,
elements = 1 << sigRGBbits;
if (!(gamma = xallocarray(elements, sizeof(LOCO))))
if (!(gamma = calloc(elements, sizeof(LOCO))))
return FALSE;
if (!(indices = xallocarray(maxColors, sizeof(int)))) {
if (!(indices = calloc(maxColors, sizeof(int)))) {
free(gamma);
return FALSE;
}
@ -261,7 +261,7 @@ CMapAllocateColormapPrivate(ColormapPtr pmap)
else
numColors = 1 << pmap->pVisual->nplanes;
if (!(colors = xallocarray(numColors, sizeof(LOCO))))
if (!(colors = calloc(numColors, sizeof(LOCO))))
return FALSE;
if (!(pColPriv = calloc(1, sizeof(CMapColormapRec)))) {

View File

@ -625,7 +625,7 @@ xf86SbusCmapLoadPalette(ScrnInfoPtr pScrn, int numColors, int *indices,
return;
fbcmap.count = 0;
fbcmap.index = indices[0];
fbcmap.red = data = xallocarray(numColors, 3);
fbcmap.red = data = calloc(numColors, 3);
if (!data)
return;
fbcmap.green = data + numColors;

View File

@ -158,7 +158,7 @@ xf86XvMCScreenInit(ScreenPtr pScreen,
if (noXvExtension)
return FALSE;
if (!(pAdapt = xallocarray(num_adaptors, sizeof(XvMCAdaptorRec))))
if (!(pAdapt = calloc(num_adaptors, sizeof(XvMCAdaptorRec))))
return FALSE;
if (!dixRegisterPrivateKey(&XF86XvMCScreenKeyRec, PRIVATE_SCREEN, 0)) {

View File

@ -420,7 +420,7 @@ ProcXF86DRIGetDrawableInfo(register ClientPtr client)
if (rep.numClipRects) {
/* Clip cliprects to screen dimensions (redirected windows) */
pClippedRects = xallocarray(rep.numClipRects, sizeof(drm_clip_rect_t));
pClippedRects = calloc(rep.numClipRects, sizeof(drm_clip_rect_t));
if (!pClippedRects)
return BadAlloc;

View File

@ -1602,7 +1602,7 @@ DRI2ScreenInit(ScreenPtr pScreen, DRI2InfoPtr info)
if (info->version == 3 || info->numDrivers == 0) {
/* Driver too old: use the old-style driverName field */
ds->numDrivers = info->driverName ? 1 : 2;
ds->driverNames = xallocarray(ds->numDrivers, sizeof(*ds->driverNames));
ds->driverNames = calloc(ds->numDrivers, sizeof(*ds->driverNames));
if (!ds->driverNames)
goto err_out;
@ -1623,7 +1623,7 @@ DRI2ScreenInit(ScreenPtr pScreen, DRI2InfoPtr info)
}
else {
ds->numDrivers = info->numDrivers;
ds->driverNames = xallocarray(info->numDrivers, sizeof(*ds->driverNames));
ds->driverNames = calloc(info->numDrivers, sizeof(*ds->driverNames));
if (!ds->driverNames)
goto err_out;
memcpy(ds->driverNames, info->driverNames,

View File

@ -589,7 +589,7 @@ dispatch_damages(ScrnInfoPtr scrn, xf86CrtcPtr crtc, RegionPtr dirty,
return 0;
if (num_cliprects) {
drmModeClip *clip = xallocarray(num_cliprects, sizeof(drmModeClip));
drmModeClip *clip = calloc(num_cliprects, sizeof(drmModeClip));
BoxPtr rect = REGION_RECTS(dirty);
int i;
int c = 0;

View File

@ -3799,7 +3799,7 @@ drmmode_create_lease(RRLeasePtr lease, int *fd)
if (!lease_private)
return BadAlloc;
objects = xallocarray(nobjects, sizeof (uint32_t));
objects = calloc(nobjects, sizeof(uint32_t));
if (!objects) {
free(lease_private);

View File

@ -397,7 +397,7 @@ VBEGetVBEInfo(vbeInfoPtr pVbe)
i = 0;
while (modes[i] != 0xffff)
i++;
block->VideoModePtr = xallocarray(i + 1, sizeof(CARD16));
block->VideoModePtr = calloc(i + 1, sizeof(CARD16));
memcpy(block->VideoModePtr, modes, sizeof(CARD16) * i);
block->VideoModePtr[i] = 0xffff;
@ -806,7 +806,7 @@ VBESetGetPaletteData(vbeInfoPtr pVbe, Bool set, int first, int num,
if (set)
return data;
data = xallocarray(num, sizeof(CARD32));
data = calloc(num, sizeof(CARD32));
memcpy(data, pVbe->memory, num * sizeof(CARD32));
return data;

View File

@ -228,7 +228,7 @@ InitPatterns(const char **patternlist)
for (i = 0, s = patternlist; *s; i++, s++)
if (*s == DEFAULT_LIST)
i += ARRAY_SIZE(stdPatterns) - 1 - 1;
patterns = xallocarray(i + 1, sizeof(PatternRec));
patterns = calloc(i + 1, sizeof(PatternRec));
if (!patterns) {
return NULL;
}

View File

@ -118,7 +118,7 @@ xf86CrtcCreate(ScrnInfoPtr scrn, const xf86CrtcFuncsRec * funcs)
/* Preallocate gamma at a sensible size. */
crtc->gamma_size = 256;
crtc->gamma_red = xallocarray(crtc->gamma_size, 3 * sizeof(CARD16));
crtc->gamma_red = calloc(crtc->gamma_size, 3 * sizeof(CARD16));
if (!crtc->gamma_red) {
free(crtc);
return NULL;
@ -130,7 +130,7 @@ xf86CrtcCreate(ScrnInfoPtr scrn, const xf86CrtcFuncsRec * funcs)
crtcs = reallocarray(xf86_config->crtc,
xf86_config->num_crtc + 1, sizeof(xf86CrtcPtr));
else
crtcs = xallocarray(xf86_config->num_crtc + 1, sizeof(xf86CrtcPtr));
crtcs = calloc(xf86_config->num_crtc + 1, sizeof(xf86CrtcPtr));
if (!crtcs) {
free(crtc->gamma_red);
free(crtc);
@ -674,8 +674,7 @@ xf86OutputCreate(ScrnInfoPtr scrn,
xf86_config->num_output + 1,
sizeof(xf86OutputPtr));
else
outputs = xallocarray(xf86_config->num_output + 1,
sizeof(xf86OutputPtr));
outputs = calloc(xf86_config->num_output + 1, sizeof(xf86OutputPtr));
if (!outputs) {
free(output);
return NULL;
@ -979,7 +978,7 @@ xf86PickCrtcs(ScrnInfoPtr scrn,
if (modes[n] == NULL)
return best_score;
crtcs = xallocarray(config->num_output, sizeof(xf86CrtcPtr));
crtcs = calloc(config->num_output, sizeof(xf86CrtcPtr));
if (!crtcs)
return best_score;

View File

@ -57,7 +57,7 @@ xf86_dga_get_modes(ScreenPtr pScreen)
if (!num)
return FALSE;
modes = xallocarray(num, sizeof(DGAModeRec));
modes = calloc(num, sizeof(DGAModeRec));
if (!modes)
return FALSE;

View File

@ -1060,7 +1060,7 @@ xf86RandR12CrtcNotify(RRCrtcPtr randr_crtc)
DisplayModePtr mode = &crtc->mode;
Bool ret;
randr_outputs = xallocarray(config->num_output, sizeof(RROutputPtr));
randr_outputs = calloc(config->num_output, sizeof(RROutputPtr));
if (!randr_outputs)
return FALSE;
x = crtc->x;
@ -1152,7 +1152,7 @@ xf86RandR12CrtcSet(ScreenPtr pScreen,
if (!crtc->scrn->vtSema)
return FALSE;
save_crtcs = xallocarray(config->num_output, sizeof(xf86CrtcPtr));
save_crtcs = calloc(config->num_output, sizeof(xf86CrtcPtr));
if ((randr_mode != NULL) != crtc->enabled)
changed = TRUE;
else if (randr_mode && !xf86RandRModeMatches(randr_mode, &crtc->mode))
@ -1428,7 +1428,7 @@ xf86RandR12CrtcInitGamma(xf86CrtcPtr crtc, float gamma_red, float gamma_green,
(gamma_red != 1.0f || gamma_green != 1.0f || gamma_blue != 1.0f))
return FALSE;
red = xallocarray(size, 3 * sizeof(CARD16));
red = calloc(size, 3 * sizeof(CARD16));
if (!red)
return FALSE;
@ -1595,7 +1595,7 @@ xf86RROutputSetModes(RROutputPtr randr_output, DisplayModePtr modes)
nmode++;
if (nmode) {
rrmodes = xallocarray(nmode, sizeof(RRModePtr));
rrmodes = calloc(nmode, sizeof(RRModePtr));
if (!rrmodes)
return FALSE;
@ -1650,8 +1650,8 @@ xf86RandR12SetInfo12(ScreenPtr pScreen)
int o, c, l;
int nclone;
clones = xallocarray(config->num_output, sizeof(RROutputPtr));
crtcs = xallocarray(config->num_crtc, sizeof(RRCrtcPtr));
clones = calloc(config->num_output, sizeof(RROutputPtr));
crtcs = calloc(config->num_crtc, sizeof(RRCrtcPtr));
for (o = 0; o < config->num_output; o++) {
xf86OutputPtr output = config->output[o];