Convert hw/dmx 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
dc5acaa28a
commit
0018784cdd
|
@ -204,8 +204,8 @@ dmxConfigAddDisplay(const char *name,
|
|||
{
|
||||
DMXScreenInfo *dmxScreen;
|
||||
|
||||
if (!(dmxScreens = realloc(dmxScreens,
|
||||
(dmxNumScreens + 1) * sizeof(*dmxScreens))))
|
||||
if (!(dmxScreens = reallocarray(dmxScreens, dmxNumScreens + 1,
|
||||
sizeof(*dmxScreens))))
|
||||
dmxLog(dmxFatal,
|
||||
"dmxConfigAddDisplay: realloc failed for screen %d (%s)\n",
|
||||
dmxNumScreens, name);
|
||||
|
@ -234,8 +234,8 @@ dmxConfigAddInput(const char *name, int core)
|
|||
{
|
||||
DMXInputInfo *dmxInput;
|
||||
|
||||
if (!(dmxInputs = realloc(dmxInputs,
|
||||
(dmxNumInputs + 1) * sizeof(*dmxInputs))))
|
||||
if (!(dmxInputs = reallocarray(dmxInputs, dmxNumInputs + 1,
|
||||
sizeof(*dmxInputs))))
|
||||
dmxLog(dmxFatal,
|
||||
"dmxConfigAddInput: realloc failed for input %d (%s)\n",
|
||||
dmxNumInputs, name);
|
||||
|
@ -341,7 +341,7 @@ dmxConfigCopyFromOption(DMXConfigOptionPtr o)
|
|||
for (pt = o->option; pt; pt = pt->next) {
|
||||
if (pt->string) {
|
||||
++argc;
|
||||
argv = realloc(argv, (argc + 1) * sizeof(*argv));
|
||||
argv = reallocarray(argv, argc + 1, sizeof(*argv));
|
||||
argv[argc] = (char *) pt->string;
|
||||
}
|
||||
}
|
||||
|
|
10
hw/dmx/dmx.c
10
hw/dmx/dmx.c
|
@ -427,7 +427,7 @@ ProcDMXChangeScreensAttributes(ClientPtr client)
|
|||
if (!_DMXXineramaActive())
|
||||
goto noxinerama;
|
||||
|
||||
if (!(attribs = malloc(stuff->screenCount * sizeof(*attribs))))
|
||||
if (!(attribs = xallocarray(stuff->screenCount, sizeof(*attribs))))
|
||||
return BadAlloc;
|
||||
|
||||
for (i = 0; i < stuff->screenCount; i++) {
|
||||
|
@ -624,18 +624,18 @@ ProcDMXGetWindowAttributes(ClientPtr client)
|
|||
|
||||
REQUEST_SIZE_MATCH(xDMXGetWindowAttributesReq);
|
||||
|
||||
if (!(screens = malloc(count * sizeof(*screens))))
|
||||
if (!(screens = xallocarray(count, sizeof(*screens))))
|
||||
return BadAlloc;
|
||||
if (!(windows = malloc(count * sizeof(*windows)))) {
|
||||
if (!(windows = xallocarray(count, sizeof(*windows)))) {
|
||||
free(screens);
|
||||
return BadAlloc;
|
||||
}
|
||||
if (!(pos = malloc(count * sizeof(*pos)))) {
|
||||
if (!(pos = xallocarray(count, sizeof(*pos)))) {
|
||||
free(windows);
|
||||
free(screens);
|
||||
return BadAlloc;
|
||||
}
|
||||
if (!(vis = malloc(count * sizeof(*vis)))) {
|
||||
if (!(vis = xallocarray(count, sizeof(*vis)))) {
|
||||
free(pos);
|
||||
free(windows);
|
||||
free(screens);
|
||||
|
|
|
@ -177,7 +177,7 @@ dmxStoreColors(ColormapPtr pColormap, int ndef, xColorItem * pdef)
|
|||
dmxColormapPrivPtr pCmapPriv = DMX_GET_COLORMAP_PRIV(pColormap);
|
||||
|
||||
if (dmxScreen->beDisplay && (pColormap->pVisual->class & DynamicClass)) {
|
||||
XColor *color = malloc(sizeof(*color) * ndef);
|
||||
XColor *color = xallocarray(ndef, sizeof(*color));
|
||||
int i;
|
||||
|
||||
if (color) {
|
||||
|
|
|
@ -203,7 +203,7 @@ miPointerScreenFuncRec dmxPointerCursorFuncs = {
|
|||
static int *
|
||||
dmxSLCreate(void)
|
||||
{
|
||||
int *list = malloc(dmxNumScreens * sizeof(*list));
|
||||
int *list = xallocarray(dmxNumScreens, sizeof(*list));
|
||||
int i;
|
||||
|
||||
for (i = 0; i < dmxNumScreens; i++)
|
||||
|
|
|
@ -1188,8 +1188,8 @@ dmxBERestoreRenderGlyph(void *value, XID id, void *n)
|
|||
|
||||
/* Now allocate the memory we need */
|
||||
images = calloc(len_images, sizeof(char));
|
||||
gids = malloc(glyphSet->hash.tableEntries * sizeof(Glyph));
|
||||
glyphs = malloc(glyphSet->hash.tableEntries * sizeof(XGlyphInfo));
|
||||
gids = xallocarray(glyphSet->hash.tableEntries, sizeof(Glyph));
|
||||
glyphs = xallocarray(glyphSet->hash.tableEntries, sizeof(XGlyphInfo));
|
||||
|
||||
pos = images;
|
||||
ctr = 0;
|
||||
|
|
|
@ -72,7 +72,7 @@ dmxGetFontPath(int *npaths)
|
|||
|
||||
newfp = malloc(*npaths + len);
|
||||
c = (unsigned char *) newfp;
|
||||
fp = malloc(*npaths * sizeof(*fp));
|
||||
fp = xallocarray(*npaths, sizeof(*fp));
|
||||
|
||||
memmove(newfp, paths + 1, *npaths + len - 1);
|
||||
l = *paths;
|
||||
|
@ -306,7 +306,7 @@ dmxBELoadFont(ScreenPtr pScreen, FontPtr pFont)
|
|||
if (!dmxFontPath)
|
||||
dmxLog(dmxWarning, "No default font path is set.\n");
|
||||
|
||||
goodfps = malloc(npaths * sizeof(*goodfps));
|
||||
goodfps = xallocarray(npaths, sizeof(*goodfps));
|
||||
|
||||
dmxLog(dmxError,
|
||||
"The DMX server failed to set the following font paths on "
|
||||
|
@ -354,7 +354,7 @@ dmxBELoadFont(ScreenPtr pScreen, FontPtr pFont)
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
newfp = malloc(len * sizeof(*newfp));
|
||||
newfp = xallocarray(len, sizeof(*newfp));
|
||||
for (i = 0; i < npaths; i++) {
|
||||
if (goodfps[i]) {
|
||||
int n = strlen(fp[i]);
|
||||
|
|
|
@ -397,7 +397,7 @@ dmxChangeClip(GCPtr pGC, int type, void *pvalue, int nrects)
|
|||
} else {
|
||||
if (dmxScreen->beDisplay) {
|
||||
nRects = RegionNumRects((RegionPtr) pGC->clientClip);
|
||||
pRects = malloc(nRects * sizeof(*pRects));
|
||||
pRects = xallocarray(nRects, sizeof(*pRects));
|
||||
pBox = RegionRects((RegionPtr) pGC->clientClip);
|
||||
|
||||
for (i = 0; i < nRects; i++) {
|
||||
|
|
|
@ -438,7 +438,7 @@ dmxGetColormaps(DMXScreenInfo * dmxScreen)
|
|||
int i;
|
||||
|
||||
dmxScreen->beNumDefColormaps = dmxScreen->beNumVisuals;
|
||||
dmxScreen->beDefColormaps = malloc(dmxScreen->beNumDefColormaps *
|
||||
dmxScreen->beDefColormaps = xallocarray(dmxScreen->beNumDefColormaps,
|
||||
sizeof(*dmxScreen->beDefColormaps));
|
||||
|
||||
for (i = 0; i < dmxScreen->beNumDefColormaps; i++)
|
||||
|
@ -793,7 +793,7 @@ InitOutput(ScreenInfo * pScreenInfo, int argc, char *argv[])
|
|||
nconfigs = dmxScreen->numGlxVisuals;
|
||||
}
|
||||
|
||||
configprivs = malloc(nconfigs * sizeof(dmxGlxVisualPrivate *));
|
||||
configprivs = xallocarray(nconfigs, sizeof(dmxGlxVisualPrivate *));
|
||||
|
||||
if (configs != NULL && configprivs != NULL) {
|
||||
int j;
|
||||
|
|
|
@ -390,7 +390,7 @@ dmxProcRenderAddGlyphs(ClientPtr client)
|
|||
sizeof(xRenderAddGlyphsReq) -
|
||||
(sizeof(CARD32) + sizeof(xGlyphInfo)) * nglyphs);
|
||||
|
||||
gidsCopy = malloc(sizeof(*gidsCopy) * nglyphs);
|
||||
gidsCopy = xallocarray(nglyphs, sizeof(*gidsCopy));
|
||||
for (i = 0; i < nglyphs; i++)
|
||||
gidsCopy[i] = gids[i];
|
||||
|
||||
|
@ -434,7 +434,7 @@ dmxProcRenderFreeGlyphs(ClientPtr client)
|
|||
|
||||
nglyphs = ((client->req_len << 2) - sizeof(xRenderFreeGlyphsReq)) >> 2;
|
||||
if (nglyphs) {
|
||||
gids = malloc(sizeof(*gids) * nglyphs);
|
||||
gids = xallocarray(nglyphs, sizeof(*gids));
|
||||
for (i = 0; i < nglyphs; i++)
|
||||
gids[i] = ((CARD32 *) (stuff + 1))[i];
|
||||
|
||||
|
@ -569,11 +569,11 @@ dmxProcRenderCompositeGlyphs(ClientPtr client)
|
|||
/* The following only works for Render version > 0.2 */
|
||||
|
||||
/* All of the XGlyphElt* structure sizes are identical */
|
||||
elts = malloc(nelt * sizeof(XGlyphElt8));
|
||||
elts = xallocarray(nelt, sizeof(XGlyphElt8));
|
||||
if (!elts)
|
||||
return BadAlloc;
|
||||
|
||||
glyphs = malloc(nglyph * size);
|
||||
glyphs = xallocarray(nglyph, size);
|
||||
if (!glyphs) {
|
||||
free(elts);
|
||||
return BadAlloc;
|
||||
|
@ -925,7 +925,7 @@ dmxChangePictureClip(PicturePtr pPicture, int clipType, void *value, int n)
|
|||
int nRects;
|
||||
|
||||
nRects = nBox;
|
||||
pRects = pRect = malloc(nRects * sizeof(*pRect));
|
||||
pRects = pRect = xallocarray(nRects, sizeof(*pRect));
|
||||
|
||||
while (nBox--) {
|
||||
pRect->x = pBox->x1;
|
||||
|
|
|
@ -171,7 +171,7 @@ dmxPropertyCheckOtherServers(DMXScreenInfo * dmxScreen, Atom atom)
|
|||
dmxLogOutputWarning(dmxScreen,
|
||||
"%s also running on %s\n",
|
||||
tp.value, dmxScreen->name);
|
||||
list = realloc(list, ++count * sizeof(*list));
|
||||
list = reallocarray(list, ++count, sizeof(*list));
|
||||
list[count - 1] = malloc(tp.nitems + 2);
|
||||
strncpy(list[count - 1], (char *) tp.value, tp.nitems + 1);
|
||||
}
|
||||
|
|
|
@ -969,7 +969,7 @@ dmxDoSetShape(WindowPtr pWindow)
|
|||
if (wBoundingShape(pWindow)) {
|
||||
pBox = RegionRects(wBoundingShape(pWindow));
|
||||
nRect = nBox = RegionNumRects(wBoundingShape(pWindow));
|
||||
pRectFirst = pRect = malloc(nRect * sizeof(*pRect));
|
||||
pRectFirst = pRect = xallocarray(nRect, sizeof(*pRect));
|
||||
while (nBox--) {
|
||||
pRect->x = pBox->x1;
|
||||
pRect->y = pBox->y1;
|
||||
|
@ -992,7 +992,7 @@ dmxDoSetShape(WindowPtr pWindow)
|
|||
if (wClipShape(pWindow)) {
|
||||
pBox = RegionRects(wClipShape(pWindow));
|
||||
nRect = nBox = RegionNumRects(wClipShape(pWindow));
|
||||
pRectFirst = pRect = malloc(nRect * sizeof(*pRect));
|
||||
pRectFirst = pRect = xallocarray(nRect, sizeof(*pRect));
|
||||
while (nBox--) {
|
||||
pRect->x = pBox->x1;
|
||||
pRect->y = pBox->y1;
|
||||
|
|
|
@ -284,11 +284,11 @@ CreateContext(__GLXclientState * cl,
|
|||
* allocate memory for back-end servers info
|
||||
*/
|
||||
num_be_screens = to_screen - from_screen + 1;
|
||||
glxc->real_ids = (XID *) malloc(sizeof(XID) * num_be_screens);
|
||||
glxc->real_ids = xallocarray(num_be_screens, sizeof(XID));
|
||||
if (!glxc->real_ids) {
|
||||
return BadAlloc;
|
||||
}
|
||||
glxc->real_vids = (XID *) malloc(sizeof(XID) * num_be_screens);
|
||||
glxc->real_vids = xallocarray(num_be_screens, sizeof(XID));
|
||||
if (!glxc->real_vids) {
|
||||
return BadAlloc;
|
||||
}
|
||||
|
@ -685,22 +685,16 @@ AddCurrentContext(__GLXclientState * cl, __GLXcontext * glxc, DrawablePtr pDraw)
|
|||
if (!num) {
|
||||
table = (__GLXcontext **) malloc(sizeof(__GLXcontext *));
|
||||
cl->currentDrawables = (DrawablePtr *) malloc(sizeof(DrawablePtr));
|
||||
cl->be_currentCTag =
|
||||
(GLXContextTag *) malloc(screenInfo.numScreens *
|
||||
sizeof(GLXContextTag));
|
||||
cl->be_currentCTag = xallocarray(screenInfo.numScreens,
|
||||
sizeof(GLXContextTag));
|
||||
}
|
||||
else {
|
||||
table = (__GLXcontext **) realloc(table,
|
||||
(num + 1) * sizeof(__GLXcontext *));
|
||||
cl->currentDrawables = (DrawablePtr *) realloc(cl->currentDrawables,
|
||||
(num +
|
||||
1) *
|
||||
sizeof(DrawablePtr));
|
||||
cl->be_currentCTag =
|
||||
(GLXContextTag *) realloc(cl->be_currentCTag,
|
||||
(num +
|
||||
1) * screenInfo.numScreens *
|
||||
sizeof(GLXContextTag));
|
||||
table = reallocarray(table, num + 1, sizeof(__GLXcontext *));
|
||||
cl->currentDrawables = reallocarray(cl->currentDrawables, num + 1,
|
||||
sizeof(DrawablePtr));
|
||||
cl->be_currentCTag = reallocarray(cl->be_currentCTag,
|
||||
(num + 1) * screenInfo.numScreens,
|
||||
sizeof(GLXContextTag));
|
||||
}
|
||||
table[num] = glxc;
|
||||
cl->currentDrawables[num] = pDraw;
|
||||
|
@ -1896,7 +1890,7 @@ CreateGLXPixmap(__GLXclientState * cl,
|
|||
if (!pGlxPixmap) {
|
||||
return BadAlloc;
|
||||
}
|
||||
pGlxPixmap->be_xids = (XID *) malloc(sizeof(XID) * screenInfo.numScreens);
|
||||
pGlxPixmap->be_xids = xallocarray(screenInfo.numScreens, sizeof(XID));
|
||||
if (!pGlxPixmap->be_xids) {
|
||||
free(pGlxPixmap);
|
||||
return BadAlloc;
|
||||
|
@ -3356,7 +3350,7 @@ __glXCreatePbuffer(__GLXclientState * cl, GLbyte * pc)
|
|||
return BadAlloc;
|
||||
}
|
||||
|
||||
pGlxPbuffer->be_xids = (XID *) malloc(sizeof(XID) * screenInfo.numScreens);
|
||||
pGlxPbuffer->be_xids = xallocarray(screenInfo.numScreens, sizeof(XID));
|
||||
if (!pGlxPbuffer->be_xids) {
|
||||
free(pGlxPbuffer);
|
||||
return BadAlloc;
|
||||
|
@ -3617,13 +3611,13 @@ __glXGetDrawableAttributes(__GLXclientState * cl, GLbyte * pc)
|
|||
}
|
||||
|
||||
if (reply.numAttribs) {
|
||||
attribs_size = 2 * reply.numAttribs * __GLX_SIZE_CARD32;
|
||||
attribs = (CARD32 *) malloc(attribs_size);
|
||||
attribs = xallocarray(reply.numAttribs, 2 * __GLX_SIZE_CARD32);
|
||||
if (attribs == NULL) {
|
||||
UnlockDisplay(dpy);
|
||||
SyncHandle();
|
||||
return BadAlloc;
|
||||
}
|
||||
attribs_size = 2 * reply.numAttribs * __GLX_SIZE_CARD32;
|
||||
|
||||
_XRead(dpy, (char *) attribs, attribs_size);
|
||||
}
|
||||
|
|
|
@ -129,7 +129,7 @@ CalcServerVersionAndExtensions(void)
|
|||
/*
|
||||
* read extensions strings of all back-end servers
|
||||
*/
|
||||
be_extensions = (char **) malloc(__glXNumActiveScreens * sizeof(char *));
|
||||
be_extensions = xallocarray(__glXNumActiveScreens, sizeof(char *));
|
||||
if (!be_extensions)
|
||||
return;
|
||||
|
||||
|
@ -237,10 +237,9 @@ __glXScreenInit(GLint numscreens)
|
|||
// find the set of FBConfigs that are present on all back-end
|
||||
// servers - only those configs will be supported
|
||||
*/
|
||||
__glXFBConfigs = (__GLXFBConfig **) malloc(dmxScreen0->numFBConfigs *
|
||||
(numscreens +
|
||||
1) *
|
||||
sizeof(__GLXFBConfig *));
|
||||
__glXFBConfigs =
|
||||
xallocarray(dmxScreen0->numFBConfigs * (numscreens + 1),
|
||||
sizeof(__GLXFBConfig *));
|
||||
__glXNumFBConfigs = 0;
|
||||
|
||||
for (c = 0; c < dmxScreen0->numFBConfigs; c++) {
|
||||
|
|
|
@ -86,7 +86,7 @@ void
|
|||
dmxArgAdd(dmxArg a, const char *string)
|
||||
{
|
||||
if (a->argm <= a->argc + 2)
|
||||
a->argv = realloc(a->argv, sizeof(*a->argv) * (a->argm *= 2));
|
||||
a->argv = reallocarray(a->argv, (a->argm *= 2), sizeof(*a->argv));
|
||||
a->argv[a->argc++] = strdup(string);
|
||||
a->argv[a->argc] = NULL;
|
||||
}
|
||||
|
|
|
@ -814,8 +814,8 @@ dmxInputCopyLocal(DMXInputInfo * dmxInput, DMXLocalInputInfoPtr s)
|
|||
dmxLocal->deviceId = -1;
|
||||
|
||||
++dmxInput->numDevs;
|
||||
dmxInput->devs = realloc(dmxInput->devs,
|
||||
dmxInput->numDevs * sizeof(*dmxInput->devs));
|
||||
dmxInput->devs = reallocarray(dmxInput->devs,
|
||||
dmxInput->numDevs, sizeof(*dmxInput->devs));
|
||||
dmxInput->devs[dmxInput->numDevs - 1] = dmxLocal;
|
||||
|
||||
return dmxLocal;
|
||||
|
|
|
@ -113,9 +113,8 @@ dmxPointerPutMotionEvent(DeviceIntPtr pDevice,
|
|||
int i;
|
||||
|
||||
if (!dmxLocal->history) {
|
||||
dmxLocal->history = malloc(sizeof(*dmxLocal->history)
|
||||
* (numAxes + 1)
|
||||
* DMX_MOTION_SIZE);
|
||||
dmxLocal->history = xallocarray(numAxes + 1,
|
||||
sizeof(*dmxLocal->history) * DMX_MOTION_SIZE);
|
||||
dmxLocal->head = 0;
|
||||
dmxLocal->tail = 0;
|
||||
dmxLocal->valuators = calloc(sizeof(*dmxLocal->valuators), numAxes);
|
||||
|
|
Loading…
Reference in New Issue