diff options
author | Alan Coopersmith <alan.coopersmith@oracle.com> | 2015-03-21 17:59:13 -0700 |
---|---|---|
committer | Alan Coopersmith <alan.coopersmith@oracle.com> | 2015-04-21 16:58:08 -0700 |
commit | 0018784cdde19444a8f970bc414796fc2a523a51 (patch) | |
tree | 779eb85d61f1ef33485fea8783b0d7f7080d2276 | |
parent | dc5acaa28ab9ed091f087e56046400d63f1f192a (diff) |
Convert hw/dmx to new *allocarray functions
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Reviewed-by: Matt Turner <mattst88@gmail.com>
-rw-r--r-- | hw/dmx/config/dmxconfig.c | 10 | ||||
-rw-r--r-- | hw/dmx/dmx.c | 10 | ||||
-rw-r--r-- | hw/dmx/dmxcmap.c | 2 | ||||
-rw-r--r-- | hw/dmx/dmxcursor.c | 2 | ||||
-rw-r--r-- | hw/dmx/dmxextension.c | 4 | ||||
-rw-r--r-- | hw/dmx/dmxfont.c | 6 | ||||
-rw-r--r-- | hw/dmx/dmxgc.c | 2 | ||||
-rw-r--r-- | hw/dmx/dmxinit.c | 4 | ||||
-rw-r--r-- | hw/dmx/dmxpict.c | 10 | ||||
-rw-r--r-- | hw/dmx/dmxprop.c | 2 | ||||
-rw-r--r-- | hw/dmx/dmxwindow.c | 4 | ||||
-rw-r--r-- | hw/dmx/glxProxy/glxcmds.c | 34 | ||||
-rw-r--r-- | hw/dmx/glxProxy/glxscreens.c | 9 | ||||
-rw-r--r-- | hw/dmx/input/dmxarg.c | 2 | ||||
-rw-r--r-- | hw/dmx/input/dmxinputinit.c | 4 | ||||
-rw-r--r-- | hw/dmx/input/dmxmotion.c | 5 |
16 files changed, 51 insertions, 59 deletions
diff --git a/hw/dmx/config/dmxconfig.c b/hw/dmx/config/dmxconfig.c index 2cc9ab396..1d10ec018 100644 --- a/hw/dmx/config/dmxconfig.c +++ b/hw/dmx/config/dmxconfig.c @@ -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; } } diff --git a/hw/dmx/dmx.c b/hw/dmx/dmx.c index 2988df33a..9729963da 100644 --- a/hw/dmx/dmx.c +++ b/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); diff --git a/hw/dmx/dmxcmap.c b/hw/dmx/dmxcmap.c index 450627b40..7a87a9864 100644 --- a/hw/dmx/dmxcmap.c +++ b/hw/dmx/dmxcmap.c @@ -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) { diff --git a/hw/dmx/dmxcursor.c b/hw/dmx/dmxcursor.c index 70f2bc4b4..0ef800e39 100644 --- a/hw/dmx/dmxcursor.c +++ b/hw/dmx/dmxcursor.c @@ -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++) diff --git a/hw/dmx/dmxextension.c b/hw/dmx/dmxextension.c index fcc97e3df..75d7166f3 100644 --- a/hw/dmx/dmxextension.c +++ b/hw/dmx/dmxextension.c @@ -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; diff --git a/hw/dmx/dmxfont.c b/hw/dmx/dmxfont.c index 115422d41..25a04a6f0 100644 --- a/hw/dmx/dmxfont.c +++ b/hw/dmx/dmxfont.c @@ -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]); diff --git a/hw/dmx/dmxgc.c b/hw/dmx/dmxgc.c index ec15d27aa..c4789a607 100644 --- a/hw/dmx/dmxgc.c +++ b/hw/dmx/dmxgc.c @@ -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++) { diff --git a/hw/dmx/dmxinit.c b/hw/dmx/dmxinit.c index 025dc8637..3d394c52b 100644 --- a/hw/dmx/dmxinit.c +++ b/hw/dmx/dmxinit.c @@ -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; diff --git a/hw/dmx/dmxpict.c b/hw/dmx/dmxpict.c index aaca178b9..1f1022ee6 100644 --- a/hw/dmx/dmxpict.c +++ b/hw/dmx/dmxpict.c @@ -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; diff --git a/hw/dmx/dmxprop.c b/hw/dmx/dmxprop.c index 5e306d286..4c85268b7 100644 --- a/hw/dmx/dmxprop.c +++ b/hw/dmx/dmxprop.c @@ -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); } diff --git a/hw/dmx/dmxwindow.c b/hw/dmx/dmxwindow.c index c157e1099..dcdb9ac60 100644 --- a/hw/dmx/dmxwindow.c +++ b/hw/dmx/dmxwindow.c @@ -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; diff --git a/hw/dmx/glxProxy/glxcmds.c b/hw/dmx/glxProxy/glxcmds.c index 4c500c93d..ddcb98135 100644 --- a/hw/dmx/glxProxy/glxcmds.c +++ b/hw/dmx/glxProxy/glxcmds.c @@ -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); } diff --git a/hw/dmx/glxProxy/glxscreens.c b/hw/dmx/glxProxy/glxscreens.c index 15bb1e862..508e67ed4 100644 --- a/hw/dmx/glxProxy/glxscreens.c +++ b/hw/dmx/glxProxy/glxscreens.c @@ -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++) { diff --git a/hw/dmx/input/dmxarg.c b/hw/dmx/input/dmxarg.c index 4a74b4c9e..6c21ae959 100644 --- a/hw/dmx/input/dmxarg.c +++ b/hw/dmx/input/dmxarg.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; } diff --git a/hw/dmx/input/dmxinputinit.c b/hw/dmx/input/dmxinputinit.c index 56a39df8c..cdefd9ae0 100644 --- a/hw/dmx/input/dmxinputinit.c +++ b/hw/dmx/input/dmxinputinit.c @@ -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; diff --git a/hw/dmx/input/dmxmotion.c b/hw/dmx/input/dmxmotion.c index 1642894a2..7f2cb8ed9 100644 --- a/hw/dmx/input/dmxmotion.c +++ b/hw/dmx/input/dmxmotion.c @@ -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); |