On Wed, Dec 06, 2017 at 02:47:13PM +0100, Sebastian Benoit wrote:

> Michael W. Bombardieri([email protected]) on 2017.12.06 16:58:27 +0800:
> > Hello,
> > 
> > Mostly dc(1) uses its own bstrdup() which exits on error.
> > It can be used in two more places.
> 
> i like to read
> 
>  if ((a = strdup(b)) == NULL)
>       err(1, NULL);
> 
> much more than start looking what bstrdup() does...
> 
> bstrdup() is only used in 5 places currently, why not get rid of it?

I like the diff so I comitted it. dc uses checking versions of the
allocation functions, all prefixed with a b. It's not hard to learn
that pattern and using the b functions declutters the code in a good
way.

        -Otto

> 
> /Benno
> 
> > 
> > - Michael
> > 
> > 
> > Index: dc.c
> > ===================================================================
> > RCS file: /cvs/src/usr.bin/dc/dc.c,v
> > retrieving revision 1.19
> > diff -u -p -u -r1.19 dc.c
> > --- dc.c    29 Nov 2017 14:34:17 -0000      1.19
> > +++ dc.c    6 Dec 2017 08:44:30 -0000
> > @@ -47,8 +47,7 @@ dc_main(int argc, char *argv[])
> >     char            *buf, *p;
> >     struct stat     st;
> >  
> > -   if ((buf = strdup("")) == NULL)
> > -           err(1, NULL);
> > +   buf = bstrdup("");
> >     /* accept and ignore a single dash to be 4.4BSD dc(1) compatible */
> >     optind = 1;
> >     optreset = 1;
> > Index: stack.c
> > ===================================================================
> > RCS file: /cvs/src/usr.bin/dc/stack.c,v
> > retrieving revision 1.14
> > diff -u -p -u -r1.14 stack.c
> > --- stack.c 27 Mar 2016 15:55:13 -0000      1.14
> > +++ stack.c 6 Dec 2017 08:44:30 -0000
> > @@ -79,9 +79,7 @@ stack_dup_value(const struct value *a, s
> >             copy->u.num = dup_number(a->u.num);
> >             break;
> >     case BCODE_STRING:
> > -           copy->u.string = strdup(a->u.string);
> > -           if (copy->u.string == NULL)
> > -                   err(1, NULL);
> > +           copy->u.string = bstrdup(a->u.string);
> >             break;
> >     }
> >  
> > 

Reply via email to