ok beck@

On Sun, Sep 4, 2016 at 9:54 AM, Theo Buehler <t...@math.ethz.ch> wrote:

> use the libc interface instead of rolling it by hand.
>
> Index: parse.c
> ===================================================================
> RCS file: /var/cvs/src/usr.bin/hexdump/parse.c,v
> retrieving revision 1.21
> diff -u -p -r1.21 parse.c
> --- parse.c     24 Aug 2016 03:13:45 -0000      1.21
> +++ parse.c     24 Aug 2016 05:23:47 -0000
> @@ -147,8 +147,7 @@ add(const char *fmt)
>                 for (savep = ++p; *p != '"';)
>                         if (*p++ == 0)
>                                 badfmt(fmt);
> -               tfu->fmt = strndup(savep, p - savep);
> -               if (tfu->fmt == NULL)
> +               if ((tfu->fmt = strndup(savep, p - savep)) == NULL)
>                         err(1, NULL);
>                 escape(tfu->fmt);
>                 p++;
> @@ -219,7 +218,6 @@ rewrite(FS *fs)
>         char *p1, *p2;
>         char savech, *fmtp, cs[4];
>         int nconv, prec;
> -       size_t len;
>
>         nextpr = NULL;
>         prec = 0;
> @@ -408,10 +406,8 @@ rewrite(FS *fs)
>                          */
>                         savech = *p2;
>                         p1[0] = '\0';
> -                       len = strlen(fmtp) + strlen(cs) + 1;
> -                       if ((pr->fmt = calloc(1, len)) == NULL)
> +                       if (asprintf(&pr->fmt, "%s%s", fmtp, cs) == -1)
>                                 err(1, NULL);
> -                       snprintf(pr->fmt, len, "%s%s", fmtp, cs);
>                         *p2 = savech;
>                         pr->cchar = pr->fmt + (p1 - fmtp);
>                         fmtp = p2;
>
>

Reply via email to