Convert hw/xfree86 to new *allocarray functions

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Reviewed-by: Matt Turner <mattst88@gmail.com>
This commit is contained in:
Alan Coopersmith 2015-03-21 17:12:06 -07:00
parent f59236c286
commit 4cb1034906
26 changed files with 111 additions and 107 deletions

View File

@ -105,7 +105,7 @@ AppendToList(const char *s, const char ***list, int *lines)
str = xnfstrdup(s); str = xnfstrdup(s);
for (p = strtok(str, "\n"); p; p = strtok(NULL, "\n")) { for (p = strtok(str, "\n"); p; p = strtok(NULL, "\n")) {
(*lines)++; (*lines)++;
*list = xnfrealloc(*list, (*lines + 1) * sizeof(**list)); *list = xnfreallocarray(*list, *lines + 1, sizeof(**list));
newstr = xnfalloc(strlen(p) + 2); newstr = xnfalloc(strlen(p) + 2);
strcpy(newstr, p); strcpy(newstr, p);
strcat(newstr, "\n"); strcat(newstr, "\n");

View File

@ -256,8 +256,8 @@ int
xf86AllocateEntity(void) xf86AllocateEntity(void)
{ {
xf86NumEntities++; xf86NumEntities++;
xf86Entities = xnfrealloc(xf86Entities, xf86Entities = xnfreallocarray(xf86Entities,
sizeof(EntityPtr) * xf86NumEntities); xf86NumEntities, sizeof(EntityPtr));
xf86Entities[xf86NumEntities - 1] = xnfcalloc(1, sizeof(EntityRec)); xf86Entities[xf86NumEntities - 1] = xnfcalloc(1, sizeof(EntityRec));
xf86Entities[xf86NumEntities - 1]->entityPrivates = xf86Entities[xf86NumEntities - 1]->entityPrivates =
xnfcalloc(xf86EntityPrivateCount, sizeof(DevUnion)); xnfcalloc(xf86EntityPrivateCount, sizeof(DevUnion));
@ -326,12 +326,13 @@ xf86AddEntityToScreen(ScrnInfoPtr pScrn, int entityIndex)
} }
pScrn->numEntities++; pScrn->numEntities++;
pScrn->entityList = xnfrealloc(pScrn->entityList, pScrn->entityList = xnfreallocarray(pScrn->entityList,
pScrn->numEntities * sizeof(int)); pScrn->numEntities, sizeof(int));
pScrn->entityList[pScrn->numEntities - 1] = entityIndex; pScrn->entityList[pScrn->numEntities - 1] = entityIndex;
xf86Entities[entityIndex]->inUse = TRUE; xf86Entities[entityIndex]->inUse = TRUE;
pScrn->entityInstanceList = xnfrealloc(pScrn->entityInstanceList, pScrn->entityInstanceList = xnfreallocarray(pScrn->entityInstanceList,
pScrn->numEntities * sizeof(int)); pScrn->numEntities,
sizeof(int));
pScrn->entityInstanceList[pScrn->numEntities - 1] = 0; pScrn->entityInstanceList[pScrn->numEntities - 1] = 0;
} }
@ -427,8 +428,8 @@ xf86AddDevToEntity(int entityIndex, GDevPtr dev)
pEnt = xf86Entities[entityIndex]; pEnt = xf86Entities[entityIndex];
pEnt->numInstances++; pEnt->numInstances++;
pEnt->devices = xnfrealloc(pEnt->devices, pEnt->devices = xnfreallocarray(pEnt->devices,
pEnt->numInstances * sizeof(GDevPtr)); pEnt->numInstances, sizeof(GDevPtr));
pEnt->devices[pEnt->numInstances - 1] = dev; pEnt->devices[pEnt->numInstances - 1] = dev;
dev->claimed = TRUE; dev->claimed = TRUE;
} }
@ -670,8 +671,8 @@ xf86AllocateEntityPrivateIndex(void)
idx = xf86EntityPrivateCount++; idx = xf86EntityPrivateCount++;
for (i = 0; i < xf86NumEntities; i++) { for (i = 0; i < xf86NumEntities; i++) {
pEnt = xf86Entities[i]; pEnt = xf86Entities[i];
nprivs = xnfrealloc(pEnt->entityPrivates, nprivs = xnfreallocarray(pEnt->entityPrivates,
xf86EntityPrivateCount * sizeof(DevUnion)); xf86EntityPrivateCount, sizeof(DevUnion));
/* Zero the new private */ /* Zero the new private */
memset(&nprivs[idx], 0, sizeof(DevUnion)); memset(&nprivs[idx], 0, sizeof(DevUnion));
pEnt->entityPrivates = nprivs; pEnt->entityPrivates = nprivs;

View File

@ -363,8 +363,8 @@ xf86ModulelistFromConfig(void ***optlist)
/* /*
* allocate the memory and walk the list again to fill in the pointers * allocate the memory and walk the list again to fill in the pointers
*/ */
modulearray = xnfalloc((count + 1) * sizeof(char *)); modulearray = xnfallocarray(count + 1, sizeof(char *));
optarray = xnfalloc((count + 1) * sizeof(void *)); optarray = xnfallocarray(count + 1, sizeof(void *));
count = 0; count = 0;
if (xf86configptr->conf_modules) { if (xf86configptr->conf_modules) {
modp = xf86configptr->conf_modules->mod_load_lst; modp = xf86configptr->conf_modules->mod_load_lst;
@ -429,7 +429,7 @@ xf86DriverlistFromConfig(void)
/* /*
* allocate the memory and walk the list again to fill in the pointers * allocate the memory and walk the list again to fill in the pointers
*/ */
modulearray = xnfalloc((count + 1) * sizeof(char *)); modulearray = xnfallocarray(count + 1, sizeof(char *));
count = 0; count = 0;
slp = xf86ConfigLayout.screens; slp = xf86ConfigLayout.screens;
while (slp->screen) { while (slp->screen) {
@ -493,7 +493,7 @@ xf86InputDriverlistFromConfig(void)
/* /*
* allocate the memory and walk the list again to fill in the pointers * allocate the memory and walk the list again to fill in the pointers
*/ */
modulearray = xnfalloc((count + 1) * sizeof(char *)); modulearray = xnfallocarray(count + 1, sizeof(char *));
count = 0; count = 0;
idp = xf86ConfigLayout.inputs; idp = xf86ConfigLayout.inputs;
while (idp && *idp) { while (idp && *idp) {
@ -1086,7 +1086,7 @@ addDevice(InputInfoPtr * list, InputInfoPtr pInfo)
for (devs = list; devs && *devs; devs++) for (devs = list; devs && *devs; devs++)
count++; count++;
list = xnfrealloc(list, (count + 1) * sizeof(InputInfoPtr)); list = xnfreallocarray(list, count + 1, sizeof(InputInfoPtr));
list[count] = NULL; list[count] = NULL;
list[count - 1] = pInfo; list[count - 1] = pInfo;
@ -1626,7 +1626,7 @@ configLayout(serverLayoutPtr servlayoutp, XF86ConfLayoutPtr conf_layout,
} }
DebugF("Found %d inactive devices in the layout section %s\n", DebugF("Found %d inactive devices in the layout section %s\n",
count, conf_layout->lay_identifier); count, conf_layout->lay_identifier);
gdp = xnfalloc((count + 1) * sizeof(GDevRec)); gdp = xnfallocarray(count + 1, sizeof(GDevRec));
gdp[count].identifier = NULL; gdp[count].identifier = NULL;
idp = conf_layout->lay_inactive_lst; idp = conf_layout->lay_inactive_lst;
count = 0; count = 0;
@ -1746,7 +1746,7 @@ configXvAdaptor(confXvAdaptorPtr adaptor, XF86ConfVideoAdaptorPtr conf_adaptor)
count++; count++;
conf_port = (XF86ConfVideoPortPtr) conf_port->list.next; conf_port = (XF86ConfVideoPortPtr) conf_port->list.next;
} }
adaptor->ports = xnfalloc((count) * sizeof(confXvPortRec)); adaptor->ports = xnfallocarray(count, sizeof(confXvPortRec));
adaptor->numports = count; adaptor->numports = count;
count = 0; count = 0;
conf_port = conf_adaptor->va_port_lst; conf_port = conf_adaptor->va_port_lst;
@ -1827,7 +1827,7 @@ configScreen(confScreenPtr screenp, XF86ConfScreenPtr conf_screen, int scrnum,
count++; count++;
dispptr = (XF86ConfDisplayPtr) dispptr->list.next; dispptr = (XF86ConfDisplayPtr) dispptr->list.next;
} }
screenp->displays = xnfalloc((count) * sizeof(DispRec)); screenp->displays = xnfallocarray(count, sizeof(DispRec));
screenp->numdisplays = count; screenp->numdisplays = count;
/* Fill in the default Virtual size, if any */ /* Fill in the default Virtual size, if any */
@ -1857,7 +1857,7 @@ configScreen(confScreenPtr screenp, XF86ConfScreenPtr conf_screen, int scrnum,
count++; count++;
conf_adaptor = (XF86ConfAdaptorLinkPtr) conf_adaptor->list.next; conf_adaptor = (XF86ConfAdaptorLinkPtr) conf_adaptor->list.next;
} }
screenp->xvadaptors = xnfalloc((count) * sizeof(confXvAdaptorRec)); screenp->xvadaptors = xnfallocarray(count, sizeof(confXvAdaptorRec));
screenp->numxvadaptors = 0; screenp->numxvadaptors = 0;
conf_adaptor = conf_screen->scrn_adaptor_lst; conf_adaptor = conf_screen->scrn_adaptor_lst;
while (conf_adaptor) { while (conf_adaptor) {
@ -2096,7 +2096,7 @@ configDisplay(DispPtr displayp, XF86ConfDisplayPtr conf_display)
count++; count++;
modep = (XF86ModePtr) modep->list.next; modep = (XF86ModePtr) modep->list.next;
} }
displayp->modes = xnfalloc((count + 1) * sizeof(char *)); displayp->modes = xnfallocarray(count + 1, sizeof(char *));
modep = conf_display->disp_mode_lst; modep = conf_display->disp_mode_lst;
count = 0; count = 0;
while (modep) { while (modep) {

View File

@ -109,7 +109,7 @@ xf86AddBusDeviceToConfigure(const char *driver, BusType bus, void *busData,
/* Allocate new structure occurrence */ /* Allocate new structure occurrence */
i = nDevToConfig++; i = nDevToConfig++;
DevToConfig = DevToConfig =
xnfrealloc(DevToConfig, nDevToConfig * sizeof(DevToConfigRec)); xnfreallocarray(DevToConfig, nDevToConfig, sizeof(DevToConfigRec));
memset(DevToConfig + i, 0, sizeof(DevToConfigRec)); memset(DevToConfig + i, 0, sizeof(DevToConfigRec));
DevToConfig[i].GDev.chipID = DevToConfig[i].GDev.chipID =

View File

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

View File

@ -77,8 +77,8 @@ xf86AddDriver(DriverPtr driver, void *module, int flags)
xf86NumDrivers = 0; xf86NumDrivers = 0;
xf86NumDrivers++; xf86NumDrivers++;
xf86DriverList = xnfrealloc(xf86DriverList, xf86DriverList = xnfreallocarray(xf86DriverList,
xf86NumDrivers * sizeof(DriverPtr)); xf86NumDrivers, sizeof(DriverPtr));
xf86DriverList[xf86NumDrivers - 1] = xnfalloc(sizeof(DriverRec)); xf86DriverList[xf86NumDrivers - 1] = xnfalloc(sizeof(DriverRec));
if (flags & HaveDriverFuncs) if (flags & HaveDriverFuncs)
*xf86DriverList[xf86NumDrivers - 1] = *driver; *xf86DriverList[xf86NumDrivers - 1] = *driver;
@ -117,9 +117,9 @@ xf86AddInputDriver(InputDriverPtr driver, void *module, int flags)
xf86NumInputDrivers = 0; xf86NumInputDrivers = 0;
xf86NumInputDrivers++; xf86NumInputDrivers++;
xf86InputDriverList = xnfrealloc(xf86InputDriverList, xf86InputDriverList = xnfreallocarray(xf86InputDriverList,
xf86NumInputDrivers * xf86NumInputDrivers,
sizeof(InputDriverPtr)); sizeof(InputDriverPtr));
xf86InputDriverList[xf86NumInputDrivers - 1] = xf86InputDriverList[xf86NumInputDrivers - 1] =
xnfalloc(sizeof(InputDriverRec)); xnfalloc(sizeof(InputDriverRec));
*xf86InputDriverList[xf86NumInputDrivers - 1] = *driver; *xf86InputDriverList[xf86NumInputDrivers - 1] = *driver;
@ -173,7 +173,8 @@ xf86AllocateScreen(DriverPtr drv, int flags)
if (xf86GPUScreens == NULL) if (xf86GPUScreens == NULL)
xf86NumGPUScreens = 0; xf86NumGPUScreens = 0;
i = xf86NumGPUScreens++; i = xf86NumGPUScreens++;
xf86GPUScreens = xnfrealloc(xf86GPUScreens, xf86NumGPUScreens * sizeof(ScrnInfoPtr)); xf86GPUScreens = xnfreallocarray(xf86GPUScreens, xf86NumGPUScreens,
sizeof(ScrnInfoPtr));
xf86GPUScreens[i] = xnfcalloc(sizeof(ScrnInfoRec), 1); xf86GPUScreens[i] = xnfcalloc(sizeof(ScrnInfoRec), 1);
pScrn = xf86GPUScreens[i]; pScrn = xf86GPUScreens[i];
pScrn->scrnIndex = i + GPU_SCREEN_OFFSET; /* Changes when a screen is removed */ pScrn->scrnIndex = i + GPU_SCREEN_OFFSET; /* Changes when a screen is removed */
@ -183,7 +184,8 @@ xf86AllocateScreen(DriverPtr drv, int flags)
xf86NumScreens = 0; xf86NumScreens = 0;
i = xf86NumScreens++; i = xf86NumScreens++;
xf86Screens = xnfrealloc(xf86Screens, xf86NumScreens * sizeof(ScrnInfoPtr)); xf86Screens = xnfreallocarray(xf86Screens, xf86NumScreens,
sizeof(ScrnInfoPtr));
xf86Screens[i] = xnfcalloc(sizeof(ScrnInfoRec), 1); xf86Screens[i] = xnfcalloc(sizeof(ScrnInfoRec), 1);
pScrn = xf86Screens[i]; pScrn = xf86Screens[i];
@ -293,16 +295,16 @@ xf86AllocateScrnInfoPrivateIndex(void)
idx = xf86ScrnInfoPrivateCount++; idx = xf86ScrnInfoPrivateCount++;
for (i = 0; i < xf86NumScreens; i++) { for (i = 0; i < xf86NumScreens; i++) {
pScr = xf86Screens[i]; pScr = xf86Screens[i];
nprivs = xnfrealloc(pScr->privates, nprivs = xnfreallocarray(pScr->privates,
xf86ScrnInfoPrivateCount * sizeof(DevUnion)); xf86ScrnInfoPrivateCount, sizeof(DevUnion));
/* Zero the new private */ /* Zero the new private */
memset(&nprivs[idx], 0, sizeof(DevUnion)); memset(&nprivs[idx], 0, sizeof(DevUnion));
pScr->privates = nprivs; pScr->privates = nprivs;
} }
for (i = 0; i < xf86NumGPUScreens; i++) { for (i = 0; i < xf86NumGPUScreens; i++) {
pScr = xf86GPUScreens[i]; pScr = xf86GPUScreens[i];
nprivs = xnfrealloc(pScr->privates, nprivs = xnfreallocarray(pScr->privates,
xf86ScrnInfoPrivateCount * sizeof(DevUnion)); xf86ScrnInfoPrivateCount, sizeof(DevUnion));
/* Zero the new private */ /* Zero the new private */
memset(&nprivs[idx], 0, sizeof(DevUnion)); memset(&nprivs[idx], 0, sizeof(DevUnion));
pScr->privates = nprivs; pScr->privates = nprivs;
@ -636,8 +638,8 @@ xf86SetDepthBpp(ScrnInfoPtr scrp, int depth, int dummy, int fbbpp,
if (i == scrp->confScreen->numdisplays) { if (i == scrp->confScreen->numdisplays) {
scrp->confScreen->numdisplays++; scrp->confScreen->numdisplays++;
scrp->confScreen->displays = scrp->confScreen->displays =
xnfrealloc(scrp->confScreen->displays, xnfreallocarray(scrp->confScreen->displays,
scrp->confScreen->numdisplays * sizeof(DispRec)); scrp->confScreen->numdisplays, sizeof(DispRec));
xf86DrvMsg(scrp->scrnIndex, X_INFO, xf86DrvMsg(scrp->scrnIndex, X_INFO,
"Creating default Display subsection in Screen section\n" "Creating default Display subsection in Screen section\n"
"\t\"%s\" for depth/fbbpp %d/%d\n", "\t\"%s\" for depth/fbbpp %d/%d\n",
@ -1408,7 +1410,7 @@ xf86MatchDevice(const char *drivername, GDevPtr ** sectlist)
/* /*
* we have a matching driver that wasn't claimed, yet * we have a matching driver that wasn't claimed, yet
*/ */
pgdp = xnfrealloc(pgdp, (i + 2) * sizeof(GDevPtr)); pgdp = xnfreallocarray(pgdp, i + 2, sizeof(GDevPtr));
pgdp[i++] = screensecptr->device; pgdp[i++] = screensecptr->device;
} }
} }
@ -1420,7 +1422,7 @@ xf86MatchDevice(const char *drivername, GDevPtr ** sectlist)
if (gdp->driver && !gdp->claimed && if (gdp->driver && !gdp->claimed &&
!xf86NameCmp(gdp->driver, drivername)) { !xf86NameCmp(gdp->driver, drivername)) {
/* we have a matching driver that wasn't claimed yet */ /* we have a matching driver that wasn't claimed yet */
pgdp = xnfrealloc(pgdp, (i + 2) * sizeof(GDevPtr)); pgdp = xnfreallocarray(pgdp, i + 2, sizeof(GDevPtr));
pgdp[i++] = gdp; pgdp[i++] = gdp;
} }
j++; j++;

View File

@ -867,8 +867,9 @@ xf86NewInputDevice(InputInfoPtr pInfo, DeviceIntPtr *pdev, BOOL enable)
if (fd != -1) { if (fd != -1) {
if (paused) { if (paused) {
/* Put on new_input_devices list for delayed probe */ /* Put on new_input_devices list for delayed probe */
new_input_devices = xnfrealloc(new_input_devices, new_input_devices = xnfreallocarray(new_input_devices,
sizeof(pInfo) * (new_input_devices_count + 1)); new_input_devices_count + 1,
sizeof(pInfo));
new_input_devices[new_input_devices_count] = pInfo; new_input_devices[new_input_devices_count] = pInfo;
new_input_devices_count++; new_input_devices_count++;
systemd_logind_release_fd(pInfo->major, pInfo->minor, fd); systemd_logind_release_fd(pInfo->major, pInfo->minor, fd);

View File

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

View File

@ -317,16 +317,17 @@ localRegisterFreeBoxCallback(ScreenPtr pScreen,
offman = (FBManagerPtr) dixLookupPrivate(&pScreen->devPrivates, offman = (FBManagerPtr) dixLookupPrivate(&pScreen->devPrivates,
xf86FBScreenKey); xf86FBScreenKey);
newCallbacks = realloc(offman->FreeBoxesUpdateCallback, newCallbacks = reallocarray(offman->FreeBoxesUpdateCallback,
sizeof(FreeBoxCallbackProcPtr) * offman->NumCallbacks + 1,
(offman->NumCallbacks + 1)); sizeof(FreeBoxCallbackProcPtr));
if (!newCallbacks) if (!newCallbacks)
return FALSE; return FALSE;
else else
offman->FreeBoxesUpdateCallback = newCallbacks; offman->FreeBoxesUpdateCallback = newCallbacks;
newPrivates = realloc(offman->devPrivates, newPrivates = reallocarray(offman->devPrivates,
sizeof(DevUnion) * (offman->NumCallbacks + 1)); offman->NumCallbacks + 1,
sizeof(DevUnion));
if (!newPrivates) if (!newPrivates)
return FALSE; return FALSE;
else else

View File

@ -103,9 +103,9 @@ xf86PciProbe(void)
while ((info = pci_device_next(iter)) != NULL) { while ((info = pci_device_next(iter)) != NULL) {
if (PCIINFOCLASSES(info->device_class)) { if (PCIINFOCLASSES(info->device_class)) {
num++; num++;
xf86PciVideoInfo = xnfrealloc(xf86PciVideoInfo, xf86PciVideoInfo = xnfreallocarray(xf86PciVideoInfo,
(sizeof(struct pci_device *) num + 1,
* (num + 1))); sizeof(struct pci_device *));
xf86PciVideoInfo[num] = NULL; xf86PciVideoInfo[num] = NULL;
xf86PciVideoInfo[num - 1] = info; xf86PciVideoInfo[num - 1] = info;
@ -679,7 +679,7 @@ xf86MatchPciInstances(const char *driverName, int vendorID,
} }
pci_iterator_destroy(iter); pci_iterator_destroy(iter);
instances = xnfalloc(max_entries * sizeof(struct Inst)); instances = xnfallocarray(max_entries, sizeof(struct Inst));
} }
iter = pci_slot_match_iterator_create(NULL); iter = pci_slot_match_iterator_create(NULL);
@ -976,7 +976,7 @@ xf86MatchPciInstances(const char *driverName, int vendorID,
/* Allocate an entry in the lists to be returned */ /* Allocate an entry in the lists to be returned */
numFound++; numFound++;
retEntities = xnfrealloc(retEntities, numFound * sizeof(int)); retEntities = xnfreallocarray(retEntities, numFound, sizeof(int));
retEntities[numFound - 1] = xf86ClaimPciSlot(pPci, drvp, retEntities[numFound - 1] = xf86ClaimPciSlot(pPci, drvp,
instances[i].chip, instances[i].chip,
instances[i].dev, instances[i].dev,

View File

@ -59,9 +59,9 @@ struct xf86_platform_device *xf86_platform_devices;
int int
xf86_add_platform_device(struct OdevAttributes *attribs, Bool unowned) xf86_add_platform_device(struct OdevAttributes *attribs, Bool unowned)
{ {
xf86_platform_devices = xnfrealloc(xf86_platform_devices, xf86_platform_devices = xnfreallocarray(xf86_platform_devices,
(sizeof(struct xf86_platform_device) xf86_num_platform_devices + 1,
* (xf86_num_platform_devices + 1))); sizeof(struct xf86_platform_device));
xf86_platform_devices[xf86_num_platform_devices].attribs = attribs; xf86_platform_devices[xf86_num_platform_devices].attribs = attribs;
xf86_platform_devices[xf86_num_platform_devices].pdev = NULL; xf86_platform_devices[xf86_num_platform_devices].pdev = NULL;

View File

@ -68,7 +68,7 @@ CheckSbusDevice(const char *device, int fbNum)
if (!sbusDeviceTable[i].devId) if (!sbusDeviceTable[i].devId)
return; return;
xf86SbusInfo = xf86SbusInfo =
xnfrealloc(xf86SbusInfo, sizeof(psdp) * (++xf86nSbusInfo + 1)); xnfreallocarray(xf86SbusInfo, ++xf86nSbusInfo + 1, sizeof(psdp));
xf86SbusInfo[xf86nSbusInfo] = NULL; xf86SbusInfo[xf86nSbusInfo] = NULL;
xf86SbusInfo[xf86nSbusInfo - 1] = psdp = xnfcalloc(sizeof(sbusDevice), 1); xf86SbusInfo[xf86nSbusInfo - 1] = psdp = xnfcalloc(sizeof(sbusDevice), 1);
psdp->devId = sbusDeviceTable[i].devId; psdp->devId = sbusDeviceTable[i].devId;
@ -406,8 +406,8 @@ xf86MatchSbusInstances(const char *driverName, int sbusDevId,
if (psdp->fd == -2) if (psdp->fd == -2)
continue; continue;
++allocatedInstances; ++allocatedInstances;
instances = xnfrealloc(instances, instances = xnfreallocarray(instances,
allocatedInstances * sizeof(struct Inst)); allocatedInstances, sizeof(struct Inst));
instances[allocatedInstances - 1].sbus = psdp; instances[allocatedInstances - 1].sbus = psdp;
instances[allocatedInstances - 1].dev = NULL; instances[allocatedInstances - 1].dev = NULL;
instances[allocatedInstances - 1].claimed = FALSE; instances[allocatedInstances - 1].claimed = FALSE;
@ -532,7 +532,7 @@ xf86MatchSbusInstances(const char *driverName, int sbusDevId,
/* Allocate an entry in the lists to be returned */ /* Allocate an entry in the lists to be returned */
numFound++; numFound++;
retEntities = xnfrealloc(retEntities, numFound * sizeof(int)); retEntities = xnfreallocarray(retEntities, numFound, sizeof(int));
retEntities[numFound - 1] retEntities[numFound - 1]
= xf86ClaimSbusSlot(psdp, drvp, instances[i].dev, = xf86ClaimSbusSlot(psdp, drvp, instances[i].dev,
instances[i].dev->active ? TRUE : FALSE); instances[i].dev->active ? TRUE : FALSE);
@ -648,7 +648,7 @@ xf86SbusCmapLoadPalette(ScrnInfoPtr pScrn, int numColors, int *indices,
return; return;
fbcmap.count = 0; fbcmap.count = 0;
fbcmap.index = indices[0]; fbcmap.index = indices[0];
fbcmap.red = data = malloc(numColors * 3); fbcmap.red = data = xallocarray(numColors, 3);
if (!data) if (!data)
return; return;
fbcmap.green = data + numColors; fbcmap.green = data + numColors;

View File

@ -1240,11 +1240,11 @@ ProcXF86VidModeGetMonitor(ClientPtr client)
pad_to_int32(rep.modelLength)); pad_to_int32(rep.modelLength));
rep.nhsync = nHsync; rep.nhsync = nHsync;
rep.nvsync = nVrefresh; rep.nvsync = nVrefresh;
hsyncdata = malloc(nHsync * sizeof(CARD32)); hsyncdata = xallocarray(nHsync, sizeof(CARD32));
if (!hsyncdata) { if (!hsyncdata) {
return BadAlloc; return BadAlloc;
} }
vsyncdata = malloc(nVrefresh * sizeof(CARD32)); vsyncdata = xallocarray(nVrefresh, sizeof(CARD32));
if (!vsyncdata) { if (!vsyncdata) {
free(hsyncdata); free(hsyncdata);
@ -1512,9 +1512,9 @@ ProcXF86VidModeGetGammaRamp(ClientPtr client)
length = (stuff->size + 1) & ~1; length = (stuff->size + 1) & ~1;
if (stuff->size) { if (stuff->size) {
ramplen = length * 3 * sizeof(CARD16); if (!(ramp = xallocarray(length, 3 * sizeof(CARD16))))
if (!(ramp = malloc(ramplen)))
return BadAlloc; return BadAlloc;
ramplen = length * 3 * sizeof(CARD16);
if (!VidModeGetGammaRamp(stuff->screen, stuff->size, if (!VidModeGetGammaRamp(stuff->screen, stuff->size,
ramp, ramp + length, ramp + (length * 2))) { ramp, ramp + length, ramp + (length * 2))) {

View File

@ -131,8 +131,8 @@ xf86XVRegisterGenericAdaptorDriver(xf86XVInitGenericAdaptorPtr InitFunc)
{ {
xf86XVInitGenericAdaptorPtr *newdrivers; xf86XVInitGenericAdaptorPtr *newdrivers;
newdrivers = realloc(GenDrivers, sizeof(xf86XVInitGenericAdaptorPtr) * newdrivers = reallocarray(GenDrivers, 1 + NumGenDrivers,
(1 + NumGenDrivers)); sizeof(xf86XVInitGenericAdaptorPtr));
if (!newdrivers) if (!newdrivers)
return 0; return 0;
GenDrivers = newdrivers; GenDrivers = newdrivers;
@ -159,7 +159,7 @@ xf86XVListGenericAdaptors(ScrnInfoPtr pScrn, XF86VideoAdaptorPtr ** adaptors)
n = (*GenDrivers[i]) (pScrn, &DrivAdap); n = (*GenDrivers[i]) (pScrn, &DrivAdap);
if (0 == n) if (0 == n)
continue; continue;
new = realloc(*adaptors, sizeof(XF86VideoAdaptorPtr) * (num + n)); new = reallocarray(*adaptors, num + n, sizeof(XF86VideoAdaptorPtr));
if (NULL == new) if (NULL == new)
continue; continue;
*adaptors = new; *adaptors = new;
@ -436,8 +436,8 @@ xf86XVInitAdaptors(ScreenPtr pScreen, XF86VideoAdaptorPtr * infoPtr, int number)
void *moreSpace; void *moreSpace;
totFormat *= 2; totFormat *= 2;
moreSpace = realloc(pFormat, moreSpace = reallocarray(pFormat, totFormat,
totFormat * sizeof(XvFormatRec)); sizeof(XvFormatRec));
if (!moreSpace) if (!moreSpace)
break; break;
pFormat = moreSpace; pFormat = moreSpace;

View File

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

View File

@ -437,7 +437,7 @@ xf86DoEEDID(ScrnInfoPtr pScrn, I2CBusPtr pBus, Bool complete)
int i, n = EDID_block[0x7e]; int i, n = EDID_block[0x7e];
if (complete && n) { if (complete && n) {
EDID_block = realloc(EDID_block, EDID1_LEN * (1 + n)); EDID_block = reallocarray(EDID_block, 1 + n, EDID1_LEN);
for (i = 0; i < n; i++) for (i = 0; i < n; i++)
DDC2Read(dev, i + 1, EDID_block + (EDID1_LEN * (1 + i))); DDC2Read(dev, i + 1, EDID_block + (EDID1_LEN * (1 + i)));

View File

@ -422,7 +422,7 @@ ProcXF86DRIGetDrawableInfo(register ClientPtr client)
if (rep.numClipRects) { if (rep.numClipRects) {
/* Clip cliprects to screen dimensions (redirected windows) */ /* Clip cliprects to screen dimensions (redirected windows) */
pClippedRects = malloc(rep.numClipRects * sizeof(drm_clip_rect_t)); pClippedRects = xallocarray(rep.numClipRects, sizeof(drm_clip_rect_t));
if (pClippedRects) { if (pClippedRects) {
ScreenPtr pScreen = screenInfo.screens[stuff->screen]; ScreenPtr pScreen = screenInfo.screens[stuff->screen];

View File

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

View File

@ -451,7 +451,7 @@ dispatch_dirty_region(ScrnInfoPtr scrn,
int ret = 0; int ret = 0;
if (num_cliprects) { if (num_cliprects) {
drmModeClip *clip = malloc(num_cliprects * sizeof(drmModeClip)); drmModeClip *clip = xallocarray(num_cliprects, sizeof(drmModeClip));
BoxPtr rect = REGION_RECTS(dirty); BoxPtr rect = REGION_RECTS(dirty);
int i; int i;

View File

@ -872,7 +872,7 @@ xf86I2CGetScreenBuses(int scrnIndex, I2CBusPtr ** pppI2CBus)
if (!pppI2CBus) if (!pppI2CBus)
continue; continue;
*pppI2CBus = xnfrealloc(*pppI2CBus, n * sizeof(I2CBusPtr)); *pppI2CBus = xnfreallocarray(*pppI2CBus, n, sizeof(I2CBusPtr));
(*pppI2CBus)[n - 1] = pI2CBus; (*pppI2CBus)[n - 1] = pI2CBus;
} }

View File

@ -142,7 +142,7 @@ InitPathList(const char *path)
if (addslash) if (addslash)
len++; len++;
save = list; save = list;
list = realloc(list, (n + 2) * sizeof(char *)); list = reallocarray(list, n + 2, sizeof(char *));
if (!list) { if (!list) {
if (save) { if (save) {
save[n] = NULL; save[n] = NULL;
@ -244,7 +244,7 @@ InitPatterns(const char **patternlist)
for (i = 0, s = patternlist; *s; i++, s++) for (i = 0, s = patternlist; *s; i++, s++)
if (*s == DEFAULT_LIST) if (*s == DEFAULT_LIST)
i += sizeof(stdPatterns) / sizeof(stdPatterns[0]) - 1 - 1; i += sizeof(stdPatterns) / sizeof(stdPatterns[0]) - 1 - 1;
patterns = malloc((i + 1) * sizeof(PatternRec)); patterns = xallocarray(i + 1, sizeof(PatternRec));
if (!patterns) { if (!patterns) {
return NULL; return NULL;
} }
@ -323,7 +323,7 @@ InitSubdirs(const char **subdirlist)
} }
} }
} }
subdirs = malloc((i * 2 + 1) * sizeof(char *)); subdirs = xallocarray(i * 2 + 1, sizeof(char *));
if (!subdirs) { if (!subdirs) {
free(tmp_subdirlist); free(tmp_subdirlist);
return NULL; return NULL;
@ -530,8 +530,8 @@ LoaderListDirs(const char **subdirlist, const char **patternlist)
match[1].rm_so != -1) { match[1].rm_so != -1) {
len = match[1].rm_eo - match[1].rm_so; len = match[1].rm_eo - match[1].rm_so;
save = listing; save = listing;
listing = realloc(listing, listing = reallocarray(listing, n + 2,
(n + 2) * sizeof(char *)); sizeof(char *));
if (!listing) { if (!listing) {
if (save) { if (save) {
save[n] = NULL; save[n] = NULL;

View File

@ -118,7 +118,7 @@ xf86CrtcCreate(ScrnInfoPtr scrn, const xf86CrtcFuncsRec * funcs)
/* Preallocate gamma at a sensible size. */ /* Preallocate gamma at a sensible size. */
crtc->gamma_size = 256; crtc->gamma_size = 256;
crtc->gamma_red = malloc(3 * crtc->gamma_size * sizeof(CARD16)); crtc->gamma_red = xallocarray(crtc->gamma_size, 3 * sizeof(CARD16));
if (!crtc->gamma_red) { if (!crtc->gamma_red) {
free(crtc); free(crtc);
return NULL; return NULL;
@ -127,10 +127,10 @@ xf86CrtcCreate(ScrnInfoPtr scrn, const xf86CrtcFuncsRec * funcs)
crtc->gamma_blue = crtc->gamma_green + crtc->gamma_size; crtc->gamma_blue = crtc->gamma_green + crtc->gamma_size;
if (xf86_config->crtc) if (xf86_config->crtc)
crtcs = realloc(xf86_config->crtc, crtcs = reallocarray(xf86_config->crtc,
(xf86_config->num_crtc + 1) * sizeof(xf86CrtcPtr)); xf86_config->num_crtc + 1, sizeof(xf86CrtcPtr));
else else
crtcs = malloc((xf86_config->num_crtc + 1) * sizeof(xf86CrtcPtr)); crtcs = xallocarray(xf86_config->num_crtc + 1, sizeof(xf86CrtcPtr));
if (!crtcs) { if (!crtcs) {
free(crtc->gamma_red); free(crtc->gamma_red);
free(crtc); free(crtc);
@ -620,11 +620,12 @@ xf86OutputCreate(ScrnInfoPtr scrn,
} }
if (xf86_config->output) if (xf86_config->output)
outputs = realloc(xf86_config->output, outputs = reallocarray(xf86_config->output,
(xf86_config->num_output + xf86_config->num_output + 1,
1) * sizeof(xf86OutputPtr)); sizeof(xf86OutputPtr));
else else
outputs = malloc((xf86_config->num_output + 1) * sizeof(xf86OutputPtr)); outputs = xallocarray(xf86_config->num_output + 1,
sizeof(xf86OutputPtr));
if (!outputs) { if (!outputs) {
free(output); free(output);
return NULL; return NULL;
@ -942,7 +943,7 @@ xf86PickCrtcs(ScrnInfoPtr scrn,
if (modes[n] == NULL) if (modes[n] == NULL)
return best_score; return best_score;
crtcs = malloc(config->num_output * sizeof(xf86CrtcPtr)); crtcs = xallocarray(config->num_output, sizeof(xf86CrtcPtr));
if (!crtcs) if (!crtcs)
return best_score; return best_score;
@ -2334,7 +2335,7 @@ xf86CrtcSetInitialGamma(xf86CrtcPtr crtc, float gamma_red, float gamma_green,
int i, size = 256; int i, size = 256;
CARD16 *red, *green, *blue; CARD16 *red, *green, *blue;
red = malloc(3 * size * sizeof(CARD16)); red = xallocarray(size, 3 * sizeof(CARD16));
green = red + size; green = red + size;
blue = green + size; blue = green + size;

View File

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

View File

@ -1058,7 +1058,7 @@ xf86RandR12CrtcNotify(RRCrtcPtr randr_crtc)
DisplayModePtr mode = &crtc->mode; DisplayModePtr mode = &crtc->mode;
Bool ret; Bool ret;
randr_outputs = malloc(config->num_output * sizeof(RROutputPtr)); randr_outputs = xallocarray(config->num_output, sizeof(RROutputPtr));
if (!randr_outputs) if (!randr_outputs)
return FALSE; return FALSE;
x = crtc->x; x = crtc->x;
@ -1150,7 +1150,7 @@ xf86RandR12CrtcSet(ScreenPtr pScreen,
if (!crtc->scrn->vtSema) if (!crtc->scrn->vtSema)
return FALSE; return FALSE;
save_crtcs = malloc(config->num_output * sizeof(xf86CrtcPtr)); save_crtcs = xallocarray(config->num_output, sizeof(xf86CrtcPtr));
if ((randr_mode != NULL) != crtc->enabled) if ((randr_mode != NULL) != crtc->enabled)
changed = TRUE; changed = TRUE;
else if (randr_mode && !xf86RandRModeMatches(randr_mode, &crtc->mode)) else if (randr_mode && !xf86RandRModeMatches(randr_mode, &crtc->mode))
@ -1255,9 +1255,8 @@ xf86RandR12CrtcSetGamma(ScreenPtr pScreen, RRCrtcPtr randr_crtc)
if (randr_crtc->gammaSize != crtc->gamma_size) { if (randr_crtc->gammaSize != crtc->gamma_size) {
CARD16 *tmp_ptr; CARD16 *tmp_ptr;
tmp_ptr = tmp_ptr = reallocarray(crtc->gamma_red,
realloc(crtc->gamma_red, randr_crtc->gammaSize, 3 * sizeof(CARD16));
3 * randr_crtc->gammaSize * sizeof(CARD16));
if (!tmp_ptr) if (!tmp_ptr)
return FALSE; return FALSE;
crtc->gamma_red = tmp_ptr; crtc->gamma_red = tmp_ptr;
@ -1298,9 +1297,8 @@ xf86RandR12CrtcGetGamma(ScreenPtr pScreen, RRCrtcPtr randr_crtc)
if (randr_crtc->gammaSize != crtc->gamma_size) { if (randr_crtc->gammaSize != crtc->gamma_size) {
CARD16 *tmp_ptr; CARD16 *tmp_ptr;
tmp_ptr = tmp_ptr = reallocarray(randr_crtc->gammaRed,
realloc(randr_crtc->gammaRed, crtc->gamma_size, 3 * sizeof(CARD16));
3 * crtc->gamma_size * sizeof(CARD16));
if (!tmp_ptr) if (!tmp_ptr)
return FALSE; return FALSE;
randr_crtc->gammaRed = tmp_ptr; randr_crtc->gammaRed = tmp_ptr;
@ -1394,7 +1392,7 @@ xf86RROutputSetModes(RROutputPtr randr_output, DisplayModePtr modes)
nmode++; nmode++;
if (nmode) { if (nmode) {
rrmodes = malloc(nmode * sizeof(RRModePtr)); rrmodes = xallocarray(nmode, sizeof(RRModePtr));
if (!rrmodes) if (!rrmodes)
return FALSE; return FALSE;
@ -1449,8 +1447,8 @@ xf86RandR12SetInfo12(ScreenPtr pScreen)
int o, c, l; int o, c, l;
int nclone; int nclone;
clones = malloc(config->num_output * sizeof(RROutputPtr)); clones = xallocarray(config->num_output, sizeof(RROutputPtr));
crtcs = malloc(config->num_crtc * sizeof(RRCrtcPtr)); crtcs = xallocarray(config->num_crtc, sizeof(RRCrtcPtr));
for (o = 0; o < config->num_output; o++) { for (o = 0; o < config->num_output; o++) {
xf86OutputPtr output = config->output[o]; xf86OutputPtr output = config->output[o];

View File

@ -440,7 +440,7 @@ sparcPromAssignNodes(void)
for (i = 0, j = 0; i < 32; i++) for (i = 0, j = 0; i < 32; i++)
if (devicePtrs[i] && devicePtrs[i]->fbNum == -1) if (devicePtrs[i] && devicePtrs[i]->fbNum == -1)
j++; j++;
xf86SbusInfo = xnfrealloc(xf86SbusInfo, sizeof(psdp) * (n + j + 1)); xf86SbusInfo = xnfreallocarray(xf86SbusInfo, n + j + 1, sizeof(psdp));
for (i = 0, psdpp = xf86SbusInfo; i < 32; i++) for (i = 0, psdpp = xf86SbusInfo; i < 32; i++)
if (devicePtrs[i]) { if (devicePtrs[i]) {
if (devicePtrs[i]->fbNum == -1) { if (devicePtrs[i]->fbNum == -1) {

View File

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