Commit 7ac28028 authored by Alan Coopersmith's avatar Alan Coopersmith

Convert mi & miext to new *allocarray functions

v2: remove now useless parentheses
Signed-off-by: default avatarAlan Coopersmith <alan.coopersmith@oracle.com>
Reviewed-by: default avatarMatt Turner <mattst88@gmail.com>
parent 70f4a0e6
......@@ -1187,9 +1187,9 @@ miFillSppPoly(DrawablePtr dst, GCPtr pgc, int count, /* number of points */
y = ymax - ymin + 1;
if ((count < 3) || (y <= 0))
return;
ptsOut = FirstPoint = malloc(sizeof(DDXPointRec) * y);
width = FirstWidth = malloc(sizeof(int) * y);
Marked = malloc(sizeof(int) * count);
ptsOut = FirstPoint = xallocarray(y, sizeof(DDXPointRec));
width = FirstWidth = xallocarray(y, sizeof(int));
Marked = xallocarray(count, sizeof(int));
if (!ptsOut || !width || !Marked) {
free(Marked);
......@@ -1679,8 +1679,7 @@ miGetArcPts(SppArcPtr parc, /* points to an arc */
count++;
cdt = 2 * miDcos(dt);
if (!(poly = (SppPointPtr) realloc((void *) *ppPts,
(cpt + count) * sizeof(SppPointRec))))
if (!(poly = reallocarray(*ppPts, cpt + count, sizeof(SppPointRec))))
return 0;
*ppPts = poly;
......@@ -1737,7 +1736,7 @@ addCap(miArcCapPtr * capsp, int *ncapsp, int *sizep, int end, int arcIndex)
if (*ncapsp == *sizep) {
newsize = *sizep + ADD_REALLOC_STEP;
cap = (miArcCapPtr) realloc(*capsp, newsize * sizeof(**capsp));
cap = reallocarray(*capsp, newsize, sizeof(**capsp));
if (!cap)
return;
*sizep = newsize;
......@@ -1760,7 +1759,7 @@ addJoin(miArcJoinPtr * joinsp,
if (*njoinsp == *sizep) {
newsize = *sizep + ADD_REALLOC_STEP;
join = (miArcJoinPtr) realloc(*joinsp, newsize * sizeof(**joinsp));
join = reallocarray(*joinsp, newsize, sizeof(**joinsp));
if (!join)
return;
*sizep = newsize;
......@@ -1784,7 +1783,7 @@ addArc(miArcDataPtr * arcsp, int *narcsp, int *sizep, xArc * xarc)
if (*narcsp == *sizep) {
newsize = *sizep + ADD_REALLOC_STEP;
arc = (miArcDataPtr) realloc(*arcsp, newsize * sizeof(**arcsp));
arc = reallocarray(*arcsp, newsize, sizeof(**arcsp));
if (!arc)
return NULL;
*sizep = newsize;
......@@ -1890,10 +1889,10 @@ miComputeArcs(xArc * parcs, int narcs, GCPtr pGC)
isDoubleDash = (pGC->lineStyle == LineDoubleDash);
dashOffset = pGC->dashOffset;
data = malloc(narcs * sizeof(struct arcData));
data = xallocarray(narcs, sizeof(struct arcData));
if (!data)
return NULL;
arcs = malloc(sizeof(*arcs) * (isDoubleDash ? 2 : 1));
arcs = xallocarray(isDoubleDash ? 2 : 1, sizeof(*arcs));
if (!arcs) {
free(data);
return NULL;
......@@ -3081,8 +3080,8 @@ fillSpans(DrawablePtr pDrawable, GCPtr pGC)
if (nspans == 0)
return;
xSpan = xSpans = malloc(nspans * sizeof(DDXPointRec));
xWidth = xWidths = malloc(nspans * sizeof(int));
xSpan = xSpans = xallocarray(nspans, sizeof(DDXPointRec));
xWidth = xWidths = xallocarray(nspans, sizeof(int));
if (xSpans && xWidths) {
i = 0;
f = finalSpans;
......@@ -3136,7 +3135,7 @@ realFindSpan(int y)
else
change = SPAN_REALLOC;
newSize = finalSize + change;
newSpans = malloc(newSize * sizeof(struct finalSpan *));
newSpans = xallocarray(newSize, sizeof(struct finalSpan *));
if (!newSpans)
return NULL;
newMiny = finalMiny;
......
......@@ -136,11 +136,11 @@ miCopyArea(DrawablePtr pSrcDrawable,
dsty += pDstDrawable->y;
}
pptFirst = ppt = malloc(heightSrc * sizeof(DDXPointRec));
pwidthFirst = pwidth = malloc(heightSrc * sizeof(unsigned int));
pptFirst = ppt = xallocarray(heightSrc, sizeof(DDXPointRec));
pwidthFirst = pwidth = xallocarray(heightSrc, sizeof(unsigned int));
numRects = RegionNumRects(prgnSrcClip);
boxes = RegionRects(prgnSrcClip);
ordering = malloc(numRects * sizeof(unsigned int));
ordering = xallocarray(numRects, sizeof(unsigned int));
if (!pptFirst || !pwidthFirst || !ordering) {
free(ordering);
free(pwidthFirst);
......@@ -221,7 +221,7 @@ miCopyArea(DrawablePtr pSrcDrawable,
ppt++->y = y++;
*pwidth++ = width;
}
pbits = malloc(height * PixmapBytePad(width, pSrcDrawable->depth));
pbits = xallocarray(height, PixmapBytePad(width, pSrcDrawable->depth));
if (pbits) {
(*pSrcDrawable->pScreen->GetSpans) (pSrcDrawable, width, pptFirst,
(int *) pwidthFirst, height,
......@@ -398,8 +398,8 @@ miOpqStipDrawable(DrawablePtr pDraw, GCPtr pGC, RegionPtr prgnSrc,
ChangeGC(NullClient, pGCT, GCBackground, gcv);
ValidateGC((DrawablePtr) pPixmap, pGCT);
miClearDrawable((DrawablePtr) pPixmap, pGCT);
ppt = pptFirst = malloc(h * sizeof(DDXPointRec));
pwidth = pwidthFirst = malloc(h * sizeof(int));
ppt = pptFirst = xallocarray(h, sizeof(DDXPointRec));
pwidth = pwidthFirst = xallocarray(h, sizeof(int));
if (!pptFirst || !pwidthFirst) {
free(pwidthFirst);
free(pptFirst);
......@@ -746,8 +746,8 @@ miPutImage(DrawablePtr pDraw, GCPtr pGC, int depth,
break;
case ZPixmap:
ppt = pptFirst = malloc(h * sizeof(DDXPointRec));
pwidth = pwidthFirst = malloc(h * sizeof(int));
ppt = pptFirst = xallocarray(h, sizeof(DDXPointRec));
pwidth = pwidthFirst = xallocarray(h, sizeof(int));
if (!pptFirst || !pwidthFirst) {
free(pwidthFirst);
free(pptFirst);
......
......@@ -458,9 +458,9 @@ miInitVisuals(VisualPtr * visualp, DepthPtr * depthp, int *nvisualp,
ndepth++;
nvisual += visuals->count;
}
depth = malloc(ndepth * sizeof(DepthRec));
visual = malloc(nvisual * sizeof(VisualRec));
preferredCVCs = malloc(ndepth * sizeof(int));
depth = xallocarray(ndepth, sizeof(DepthRec));
visual = xallocarray(nvisual, sizeof(VisualRec));
preferredCVCs = xallocarray(ndepth, sizeof(int));
if (!depth || !visual || !preferredCVCs) {
free(depth);
free(visual);
......@@ -481,7 +481,7 @@ miInitVisuals(VisualPtr * visualp, DepthPtr * depthp, int *nvisualp,
prefp++;
vid = NULL;
if (nvtype) {
vid = malloc(nvtype * sizeof(VisualID));
vid = xallocarray(nvtype, sizeof(VisualID));
if (!vid) {
free(depth);
free(visual);
......
......@@ -62,7 +62,7 @@ miCopyRegion(DrawablePtr pSrcDrawable,
if (nbox > 1) {
/* keep ordering in each band, reverse order of bands */
pboxNew1 = (BoxPtr) malloc(sizeof(BoxRec) * nbox);
pboxNew1 = xallocarray(nbox, sizeof(BoxRec));
if (!pboxNew1)
return;
pboxBase = pboxNext = pbox + nbox - 1;
......@@ -93,7 +93,7 @@ miCopyRegion(DrawablePtr pSrcDrawable,
if (nbox > 1) {
/* reverse order of rects in each band */
pboxNew2 = (BoxPtr) malloc(sizeof(BoxRec) * nbox);
pboxNew2 = xallocarray(nbox, sizeof(BoxRec));
if (!pboxNew2) {
free(pboxNew1);
return;
......
......@@ -535,7 +535,7 @@ miPaintWindow(WindowPtr pWin, RegionPtr prgn, int what)
gcmask |= GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin;
}
prect = malloc(RegionNumRects(prgn) * sizeof(xRectangle));
prect = xallocarray(RegionNumRects(prgn), sizeof(xRectangle));
if (!prect)
return;
......
......@@ -100,8 +100,8 @@ miPolyFillRect(DrawablePtr pDrawable, GCPtr pGC, int nrectFill, /* number of rec
maxheight = max(maxheight, prect->height);
}
pptFirst = malloc(maxheight * sizeof(DDXPointRec));
pwFirst = malloc(maxheight * sizeof(int));
pptFirst = xallocarray(maxheight, sizeof(DDXPointRec));
pwFirst = xallocarray(maxheight, sizeof(int));
if (!pptFirst || !pwFirst) {
free(pwFirst);
free(pptFirst);
......
......@@ -131,7 +131,7 @@ miPolyGlyphBlt(DrawablePtr pDrawable, GC * pGC, int x, int y, unsigned int nglyp
gcvals);
nbyLine = BitmapBytePad(width);
pbits = malloc(height * nbyLine);
pbits = xallocarray(height, nbyLine);
if (!pbits) {
(*pDrawable->pScreen->DestroyPixmap) (pPixmap);
FreeScratchGC(pGCtmp);
......
......@@ -352,8 +352,8 @@ NewExtensionModuleList(int size)
numExtensionModules = 0;
n = numExtensionModules + size;
ExtensionModuleList = realloc(ExtensionModuleList,
n * sizeof(ExtensionModule));
ExtensionModuleList = reallocarray(ExtensionModuleList, n,
sizeof(ExtensionModule));
if (ExtensionModuleList == NULL) {
ExtensionModuleList = save;
return NULL;
......
......@@ -412,8 +412,8 @@ miFillConvexPoly(DrawablePtr dst, GCPtr pgc, int count, DDXPointPtr ptsIn)
dy = ymax - ymin + 1;
if ((count < 3) || (dy < 0))
return TRUE;
ptsOut = FirstPoint = malloc(sizeof(DDXPointRec) * dy);
width = FirstWidth = malloc(sizeof(int) * dy);
ptsOut = FirstPoint = xallocarray(dy, sizeof(DDXPointRec));
width = FirstWidth = xallocarray(dy, sizeof(int));
if (!FirstPoint || !FirstWidth) {
free(FirstWidth);
free(FirstPoint);
......
......@@ -67,7 +67,7 @@ miPolyPoint(DrawablePtr pDrawable, GCPtr pGC, int mode, /* Origin or Previous */
int i;
xPoint *ppt;
if (!(pwidthInit = malloc(npt * sizeof(int))))
if (!(pwidthInit = xallocarray(npt, sizeof(int))))
return;
/* make pointlist origin relative */
......
......@@ -88,7 +88,7 @@ miPolyRectangle(DrawablePtr pDraw, GCPtr pGC, int nrects, xRectangle *pRects)
offset2 = pGC->lineWidth;
offset1 = offset2 >> 1;
offset3 = offset2 - offset1;
tmp = malloc(ntmp * sizeof(xRectangle));
tmp = xallocarray(ntmp, sizeof(xRectangle));
if (!tmp)
return;
t = tmp;
......
......@@ -189,19 +189,16 @@ miSubtractSpans(SpanGroup * spanGroup, Spans * sub)
int *newwid;
#define EXTRA 8
newPt =
(DDXPointPtr) realloc(spans->points,
(spans->count +
EXTRA) *
sizeof(DDXPointRec));
newPt = reallocarray(spans->points,
spans->count + EXTRA,
sizeof(DDXPointRec));
if (!newPt)
break;
spansPt = newPt + (spansPt - spans->points);
spans->points = newPt;
newwid =
(int *) realloc(spans->widths,
(spans->count +
EXTRA) * sizeof(int));
newwid = reallocarray(spans->widths,
spans->count + EXTRA,
sizeof(int));
if (!newwid)
break;
spansWid = newwid + (spansWid - spans->widths);
......@@ -240,8 +237,8 @@ miAppendSpans(SpanGroup * spanGroup, SpanGroup * otherGroup, Spans * spans)
if (spansCount > 0) {
if (spanGroup->size == spanGroup->count) {
spanGroup->size = (spanGroup->size + 8) * 2;
spanGroup->group = (Spans *)
realloc(spanGroup->group, sizeof(Spans) * spanGroup->size);
spanGroup->group =
reallocarray(spanGroup->group, sizeof(Spans), spanGroup->size);
}
spanGroup->group[spanGroup->count] = *spans;
......@@ -456,8 +453,8 @@ miFillUniqueSpanGroup(DrawablePtr pDraw, GCPtr pGC, SpanGroup * spanGroup)
ylength = spanGroup->ymax - ymin + 1;
/* Allocate Spans for y buckets */
yspans = malloc(ylength * sizeof(Spans));
ysizes = malloc(ylength * sizeof(int));
yspans = xallocarray(ylength, sizeof(Spans));
ysizes = xallocarray(ylength, sizeof(int));
if (!yspans || !ysizes) {
free(yspans);
......@@ -491,12 +488,11 @@ miFillUniqueSpanGroup(DrawablePtr pDraw, GCPtr pGC, SpanGroup * spanGroup)
int *newwidths;
ysizes[index] = (ysizes[index] + 8) * 2;
newpoints = (DDXPointPtr) realloc(newspans->points,
ysizes[index] *
sizeof(DDXPointRec));
newwidths =
(int *) realloc(newspans->widths,
ysizes[index] * sizeof(int));
newpoints = reallocarray(newspans->points,
ysizes[index],
sizeof(DDXPointRec));
newwidths = reallocarray(newspans->widths,
ysizes[index], sizeof(int));
if (!newpoints || !newwidths) {
for (i = 0; i < ylength; i++) {
free(yspans[i].points);
......@@ -525,8 +521,8 @@ miFillUniqueSpanGroup(DrawablePtr pDraw, GCPtr pGC, SpanGroup * spanGroup)
} /* for i thorough Spans */
/* Now sort by x and uniquify each bucket into the final array */
points = malloc(count * sizeof(DDXPointRec));
widths = malloc(count * sizeof(int));
points = xallocarray(count, sizeof(DDXPointRec));
widths = xallocarray(count, sizeof(int));
if (!points || !widths) {
for (i = 0; i < ylength; i++) {
free(yspans[i].points);
......@@ -573,10 +569,10 @@ miFillUniqueSpanGroup(DrawablePtr pDraw, GCPtr pGC, SpanGroup * spanGroup)
static Bool
InitSpans(Spans * spans, size_t nspans)
{
spans->points = malloc(nspans * sizeof(*spans->points));
spans->points = xallocarray(nspans, sizeof(*spans->points));
if (!spans->points)
return FALSE;
spans->widths = malloc(nspans * sizeof(*spans->widths));
spans->widths = xallocarray(nspans, sizeof(*spans->widths));
if (!spans->widths) {
free(spans->points);
return FALSE;
......
......@@ -777,9 +777,9 @@ miSpriteTrace(SpritePtr pSprite, int x, int y)
) {
if (pSprite->spriteTraceGood >= pSprite->spriteTraceSize) {
pSprite->spriteTraceSize += 10;
pSprite->spriteTrace = realloc(pSprite->spriteTrace,
pSprite->spriteTraceSize *
sizeof(WindowPtr));
pSprite->spriteTrace = reallocarray(pSprite->spriteTrace,
pSprite->spriteTraceSize,
sizeof(WindowPtr));
}
pSprite->spriteTrace[pSprite->spriteTraceGood++] = pWin;
pWin = pWin->firstChild;
......
......@@ -671,7 +671,7 @@ miZeroPolyArc(DrawablePtr pDraw, GCPtr pGC, int narcs, xArc * parcs)
numPts = maxPts << 2;
dospans = (pGC->fillStyle != FillSolid);
if (dospans) {
widths = malloc(sizeof(int) * numPts);
widths = xallocarray(numPts, sizeof(int));
if (!widths)
return;
maxw = 0;
......@@ -687,7 +687,7 @@ miZeroPolyArc(DrawablePtr pDraw, GCPtr pGC, int narcs, xArc * parcs)
(unsigned char *) pGC->dash, (int) pGC->numInDashList,
&dinfo.dashOffsetInit);
}
points = malloc(sizeof(DDXPointRec) * numPts);
points = xallocarray(numPts, sizeof(DDXPointRec));
if (!points) {
if (dospans) {
free(widths);
......
......@@ -150,8 +150,8 @@ miZeroLine(DrawablePtr pDraw, GCPtr pGC, int mode, /* Origin or Previous */
width = xright - xleft + 1;
height = ybottom - ytop + 1;
list_len = (height >= width) ? height : width;
pspanInit = malloc(list_len * sizeof(DDXPointRec));
pwidthInit = malloc(list_len * sizeof(int));
pspanInit = xallocarray(list_len, sizeof(DDXPointRec));
pwidthInit = xallocarray(list_len, sizeof(int));
if (!pspanInit || !pwidthInit) {
free(pspanInit);
free(pwidthInit);
......
......@@ -1293,7 +1293,7 @@ damageText(DrawablePtr pDrawable,
if (!checkGCDamage(pDrawable, pGC))
return;
charinfo = malloc(count * sizeof(CharInfoPtr));
charinfo = xallocarray(count, sizeof(CharInfoPtr));
if (!charinfo)
return;
......
......@@ -949,7 +949,7 @@ StartFrameResize(WindowPtr pWin, Bool gravity,
copy_rect_width = copy_rect.x2 - copy_rect.x1;
copy_rect_height = copy_rect.y2 - copy_rect.y1;
copy_rowbytes = ((copy_rect_width * Bpp) + 31) & ~31;
gResizeDeathBits = malloc(copy_rowbytes * copy_rect_height);
gResizeDeathBits = xallocarray(copy_rowbytes, copy_rect_height);
if (copy_rect_width * copy_rect_height >
rootless_CopyBytes_threshold &&
......@@ -998,7 +998,7 @@ StartFrameResize(WindowPtr pWin, Bool gravity,
RootlessStartDrawing(pWin);
gResizeDeathBits = malloc(winRec->bytesPerRow * winRec->height);
gResizeDeathBits = xallocarray(winRec->bytesPerRow, winRec->height);
memcpy(gResizeDeathBits, winRec->pixelData,
winRec->bytesPerRow * winRec->height);
......
......@@ -44,6 +44,6 @@ shadowAlloc(int width, int height, int bpp)
/* Cant use PixmapBytePad -- the structure is probably not initialized yet */
stride = BitmapBytePad(width * bpp);
fb = malloc(stride * height);
fb = xallocarray(stride, height);
return fb;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment