diff options
-rw-r--r-- | mi/miarc.c | 25 | ||||
-rw-r--r-- | mi/mibitblt.c | 16 | ||||
-rw-r--r-- | mi/micmap.c | 8 | ||||
-rw-r--r-- | mi/micopy.c | 4 | ||||
-rw-r--r-- | mi/miexpose.c | 2 | ||||
-rw-r--r-- | mi/mifillrct.c | 4 | ||||
-rw-r--r-- | mi/miglblt.c | 2 | ||||
-rw-r--r-- | mi/miinitext.c | 4 | ||||
-rw-r--r-- | mi/mipoly.c | 4 | ||||
-rw-r--r-- | mi/mipolypnt.c | 2 | ||||
-rw-r--r-- | mi/mipolyrect.c | 2 | ||||
-rw-r--r-- | mi/miwideline.c | 42 | ||||
-rw-r--r-- | mi/miwindow.c | 6 | ||||
-rw-r--r-- | mi/mizerarc.c | 4 | ||||
-rw-r--r-- | mi/mizerline.c | 4 | ||||
-rw-r--r-- | miext/damage/damage.c | 2 | ||||
-rw-r--r-- | miext/rootless/rootlessWindow.c | 4 | ||||
-rw-r--r-- | miext/shadow/shalloc.c | 2 |
18 files changed, 66 insertions, 71 deletions
diff --git a/mi/miarc.c b/mi/miarc.c index e8bc87e3e..5e854b329 100644 --- a/mi/miarc.c +++ b/mi/miarc.c @@ -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; diff --git a/mi/mibitblt.c b/mi/mibitblt.c index 724396333..28296a449 100644 --- a/mi/mibitblt.c +++ b/mi/mibitblt.c @@ -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); diff --git a/mi/micmap.c b/mi/micmap.c index 1aeb359ba..5743adb19 100644 --- a/mi/micmap.c +++ b/mi/micmap.c @@ -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); diff --git a/mi/micopy.c b/mi/micopy.c index 2409c7880..12cdad4ad 100644 --- a/mi/micopy.c +++ b/mi/micopy.c @@ -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; diff --git a/mi/miexpose.c b/mi/miexpose.c index fc4dbc071..c4118f16a 100644 --- a/mi/miexpose.c +++ b/mi/miexpose.c @@ -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; diff --git a/mi/mifillrct.c b/mi/mifillrct.c index 28f2322e6..eb98a779e 100644 --- a/mi/mifillrct.c +++ b/mi/mifillrct.c @@ -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); diff --git a/mi/miglblt.c b/mi/miglblt.c index 0183e998b..e9d3a1af0 100644 --- a/mi/miglblt.c +++ b/mi/miglblt.c @@ -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); diff --git a/mi/miinitext.c b/mi/miinitext.c index 086d2c3fb..5fc44e3f4 100644 --- a/mi/miinitext.c +++ b/mi/miinitext.c @@ -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; diff --git a/mi/mipoly.c b/mi/mipoly.c index a332376d1..a97e2bb64 100644 --- a/mi/mipoly.c +++ b/mi/mipoly.c @@ -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); diff --git a/mi/mipolypnt.c b/mi/mipolypnt.c index 4fa521d07..1c4150dfb 100644 --- a/mi/mipolypnt.c +++ b/mi/mipolypnt.c @@ -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 */ diff --git a/mi/mipolyrect.c b/mi/mipolyrect.c index 830822513..7ebf9db8d 100644 --- a/mi/mipolyrect.c +++ b/mi/mipolyrect.c @@ -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; diff --git a/mi/miwideline.c b/mi/miwideline.c index 452d74fc1..3baa99bfb 100644 --- a/mi/miwideline.c +++ b/mi/miwideline.c @@ -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; diff --git a/mi/miwindow.c b/mi/miwindow.c index a1af3a770..7574239f5 100644 --- a/mi/miwindow.c +++ b/mi/miwindow.c @@ -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; diff --git a/mi/mizerarc.c b/mi/mizerarc.c index b216cf43d..e1b5f0c18 100644 --- a/mi/mizerarc.c +++ b/mi/mizerarc.c @@ -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); diff --git a/mi/mizerline.c b/mi/mizerline.c index 5a2447014..2f22d2309 100644 --- a/mi/mizerline.c +++ b/mi/mizerline.c @@ -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); diff --git a/miext/damage/damage.c b/miext/damage/damage.c index 6ef7f9dfc..ce20169d4 100644 --- a/miext/damage/damage.c +++ b/miext/damage/damage.c @@ -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; diff --git a/miext/rootless/rootlessWindow.c b/miext/rootless/rootlessWindow.c index a8f296a39..1f78e3f6c 100644 --- a/miext/rootless/rootlessWindow.c +++ b/miext/rootless/rootlessWindow.c @@ -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); diff --git a/miext/shadow/shalloc.c b/miext/shadow/shalloc.c index e555135b9..6a79085c4 100644 --- a/miext/shadow/shalloc.c +++ b/miext/shadow/shalloc.c @@ -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; } |