Convert hw/xnest & hw/vfb 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:
parent
4cb1034906
commit
ae2dc01cf1
|
@ -292,7 +292,7 @@ ddxProcessArgument(int argc, char *argv[], int i)
|
|||
|
||||
if (vfbNumScreens <= screenNum) {
|
||||
vfbScreens =
|
||||
realloc(vfbScreens, sizeof(*vfbScreens) * (screenNum + 1));
|
||||
reallocarray(vfbScreens, screenNum + 1, sizeof(*vfbScreens));
|
||||
if (!vfbScreens)
|
||||
FatalError("Not enough memory for screen %d\n", screenNum);
|
||||
for (; vfbNumScreens <= screenNum; ++vfbNumScreens)
|
||||
|
@ -407,9 +407,9 @@ vfbInstallColormap(ColormapPtr pmap)
|
|||
swapcopy32(pXWDHeader->bits_per_rgb, pVisual->bitsPerRGBValue);
|
||||
swapcopy32(pXWDHeader->colormap_entries, pVisual->ColormapEntries);
|
||||
|
||||
ppix = (Pixel *) malloc(entries * sizeof(Pixel));
|
||||
prgb = (xrgb *) malloc(entries * sizeof(xrgb));
|
||||
defs = (xColorItem *) malloc(entries * sizeof(xColorItem));
|
||||
ppix = xallocarray(entries, sizeof(Pixel));
|
||||
prgb = xallocarray(entries, sizeof(xrgb));
|
||||
defs = xallocarray(entries, sizeof(xColorItem));
|
||||
|
||||
for (i = 0; i < entries; i++)
|
||||
ppix[i] = i;
|
||||
|
|
|
@ -62,7 +62,7 @@ xnestCreateColormap(ColormapPtr pCmap)
|
|||
|
||||
switch (pVisual->class) {
|
||||
case StaticGray: /* read only */
|
||||
colors = (XColor *) malloc(ncolors * sizeof(XColor));
|
||||
colors = xallocarray(ncolors, sizeof(XColor));
|
||||
for (i = 0; i < ncolors; i++)
|
||||
colors[i].pixel = i;
|
||||
XQueryColors(xnestDisplay, xnestColormap(pCmap), colors, ncolors);
|
||||
|
@ -75,7 +75,7 @@ xnestCreateColormap(ColormapPtr pCmap)
|
|||
break;
|
||||
|
||||
case StaticColor: /* read only */
|
||||
colors = (XColor *) malloc(ncolors * sizeof(XColor));
|
||||
colors = xallocarray(ncolors, sizeof(XColor));
|
||||
for (i = 0; i < ncolors; i++)
|
||||
colors[i].pixel = i;
|
||||
XQueryColors(xnestDisplay, xnestColormap(pCmap), colors, ncolors);
|
||||
|
@ -88,7 +88,7 @@ xnestCreateColormap(ColormapPtr pCmap)
|
|||
break;
|
||||
|
||||
case TrueColor: /* read only */
|
||||
colors = (XColor *) malloc(ncolors * sizeof(XColor));
|
||||
colors = xallocarray(ncolors, sizeof(XColor));
|
||||
red = green = blue = 0L;
|
||||
redInc = lowbit(pVisual->redMask);
|
||||
greenInc = lowbit(pVisual->greenMask);
|
||||
|
@ -194,14 +194,12 @@ xnestSetInstalledColormapWindows(ScreenPtr pScreen)
|
|||
xnestInstalledColormapWindows icws;
|
||||
int numWindows;
|
||||
|
||||
icws.cmapIDs = (Colormap *) malloc(pScreen->maxInstalledCmaps *
|
||||
sizeof(Colormap));
|
||||
icws.cmapIDs = xallocarray(pScreen->maxInstalledCmaps, sizeof(Colormap));
|
||||
icws.numCmapIDs = xnestListInstalledColormaps(pScreen, icws.cmapIDs);
|
||||
icws.numWindows = 0;
|
||||
WalkTree(pScreen, xnestCountInstalledColormapWindows, (void *) &icws);
|
||||
if (icws.numWindows) {
|
||||
icws.windows =
|
||||
(Window *) malloc((icws.numWindows + 1) * sizeof(Window));
|
||||
icws.windows = xallocarray(icws.numWindows + 1, sizeof(Window));
|
||||
icws.index = 0;
|
||||
WalkTree(pScreen, xnestGetInstalledColormapWindows, (void *) &icws);
|
||||
icws.windows[icws.numWindows] = xnestDefaultWindows[pScreen->myNum];
|
||||
|
@ -220,8 +218,7 @@ xnestSetInstalledColormapWindows(ScreenPtr pScreen)
|
|||
#ifdef _XSERVER64
|
||||
{
|
||||
int i;
|
||||
Window64 *windows =
|
||||
(Window64 *) malloc(numWindows * sizeof(Window64));
|
||||
Window64 *windows = xallocarray(numWindows, sizeof(Window64));
|
||||
|
||||
for (i = 0; i < numWindows; ++i)
|
||||
windows[i] = icws.windows[i];
|
||||
|
@ -393,7 +390,7 @@ xnestStoreColors(ColormapPtr pCmap, int nColors, xColorItem * pColors)
|
|||
#ifdef _XSERVER64
|
||||
{
|
||||
int i;
|
||||
XColor *pColors64 = (XColor *) malloc(nColors * sizeof(XColor));
|
||||
XColor *pColors64 = xallocarray(nColors, sizeof(XColor));
|
||||
|
||||
for (i = 0; i < nColors; ++i) {
|
||||
pColors64[i].pixel = pColors[i].pixel;
|
||||
|
|
|
@ -121,8 +121,8 @@ xnestOpenDisplay(int argc, char *argv[])
|
|||
}
|
||||
|
||||
xnestNumDefaultColormaps = xnestNumVisuals;
|
||||
xnestDefaultColormaps = (Colormap *) malloc(xnestNumDefaultColormaps *
|
||||
sizeof(Colormap));
|
||||
xnestDefaultColormaps = xallocarray(xnestNumDefaultColormaps,
|
||||
sizeof(Colormap));
|
||||
for (i = 0; i < xnestNumDefaultColormaps; i++)
|
||||
xnestDefaultColormaps[i] = XCreateColormap(xnestDisplay,
|
||||
DefaultRootWindow
|
||||
|
|
|
@ -190,7 +190,7 @@ xnestDestroyGC(GCPtr pGC)
|
|||
void
|
||||
xnestChangeClip(GCPtr pGC, int type, void *pValue, int nRects)
|
||||
{
|
||||
int i, size;
|
||||
int i;
|
||||
BoxPtr pBox;
|
||||
XRectangle *pRects;
|
||||
|
||||
|
@ -204,8 +204,7 @@ xnestChangeClip(GCPtr pGC, int type, void *pValue, int nRects)
|
|||
|
||||
case CT_REGION:
|
||||
nRects = RegionNumRects((RegionPtr) pValue);
|
||||
size = nRects * sizeof(*pRects);
|
||||
pRects = (XRectangle *) malloc(size);
|
||||
pRects = xallocarray(nRects, sizeof(*pRects));
|
||||
pBox = RegionRects((RegionPtr) pValue);
|
||||
for (i = nRects; i-- > 0;) {
|
||||
pRects[i].x = pBox[i].x1;
|
||||
|
|
|
@ -134,7 +134,7 @@ xnestKeyboardProc(DeviceIntPtr pDev, int onoff)
|
|||
max_keycode - min_keycode + 1,
|
||||
&mapWidth);
|
||||
len = (max_keycode - min_keycode + 1) * mapWidth;
|
||||
keymap = (KeySym *) malloc(len * sizeof(KeySym));
|
||||
keymap = xallocarray(len, sizeof(KeySym));
|
||||
for (i = 0; i < len; ++i)
|
||||
keymap[i] = keymap64[i];
|
||||
XFree(keymap64);
|
||||
|
|
|
@ -158,7 +158,7 @@ xnestOpenScreen(ScreenPtr pScreen, int argc, char *argv[])
|
|||
if (!dixRegisterPrivateKey(&xnestCursorScreenKeyRec, PRIVATE_SCREEN, 0))
|
||||
return FALSE;
|
||||
|
||||
visuals = (VisualPtr) malloc(xnestNumVisuals * sizeof(VisualRec));
|
||||
visuals = xallocarray(xnestNumVisuals, sizeof(VisualRec));
|
||||
numVisuals = 0;
|
||||
|
||||
depths = (DepthPtr) malloc(MAXDEPTH * sizeof(DepthRec));
|
||||
|
@ -224,7 +224,7 @@ xnestOpenScreen(ScreenPtr pScreen, int argc, char *argv[])
|
|||
|
||||
numVisuals++;
|
||||
}
|
||||
visuals = (VisualPtr) realloc(visuals, numVisuals * sizeof(VisualRec));
|
||||
visuals = reallocarray(visuals, numVisuals, sizeof(VisualRec));
|
||||
|
||||
defaultVisual = visuals[xnestDefaultVisualIndex].vid;
|
||||
rootDepth = visuals[xnestDefaultVisualIndex].nplanes;
|
||||
|
|
Loading…
Reference in New Issue