[PATCH 12/17] Convert mi & miext to new *allocarray functions

Matt Turner mattst88 at gmail.com
Tue Mar 31 20:08:00 PDT 2015


On Tue, Mar 31, 2015 at 5:50 PM, Alan Coopersmith
<alan.coopersmith at oracle.com> wrote:
> Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
> ---
>  mi/miarc.c                      |   25 +++++++++++------------
>  mi/mibitblt.c                   |   16 +++++++--------
>  mi/micmap.c                     |    8 ++++----
>  mi/micopy.c                     |    4 ++--
>  mi/miexpose.c                   |    2 +-
>  mi/mifillrct.c                  |    4 ++--
>  mi/miglblt.c                    |    2 +-
>  mi/miinitext.c                  |    4 ++--
>  mi/mipoly.c                     |    4 ++--
>  mi/mipolypnt.c                  |    2 +-
>  mi/mipolyrect.c                 |    2 +-
>  mi/miwideline.c                 |   42 ++++++++++++++++++---------------------
>  mi/miwindow.c                   |    6 +++---
>  mi/mizerarc.c                   |    4 ++--
>  mi/mizerline.c                  |    4 ++--
>  miext/damage/damage.c           |    2 +-
>  miext/rootless/rootlessWindow.c |    4 ++--
>  miext/shadow/shalloc.c          |    2 +-
>  18 files changed, 66 insertions(+), 71 deletions(-)
>
> diff --git a/mi/miarc.c b/mi/miarc.c
> index e8bc87e..6a12534 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));

Extra parentheses.


More information about the xorg-devel mailing list