Convention is usually to do err(1, "strdup") with no additional text if
using err rather than errx.

But I am not sure about this change. xmalloc.c came from ssh (and is
also used by file and diff). Would it be better to keep it in sync? How
portable is strdup?



On Sun, Jun 14, 2015 at 01:38:33PM +0200, Fritjof Bornebusch wrote:
> On Wed, Jun 10, 2015 at 07:37:57PM +0200, Fritjof Bornebusch wrote:
> > On Wed, May 20, 2015 at 10:55:34AM +0200, Fritjof Bornebusch wrote:
> > > On Tue, May 19, 2015 at 08:57:06PM +0200, Fritjof Bornebusch wrote:
> > > > Hi,
> > > > 
> > > > xstrdup just wrappes strdup, so there is no need to call xmalloc and
> > > > strlcpy instead.
> > > >
> > >
> > 
> > Ping ....
> >
> 
> Without PGP stuff ....
>   
> > > Use err() instead of errx(), so errno will be printed additionally.
> > > Thanks to Tim.
> > >  
> > > > Regards,
> > > > --F.
> > > > 
> > > > 
> > > 
> > > Regards,
> > > --F.
> > > 
> > > >  
> > > 
> 
> 
> Index: xmalloc.c
> ===================================================================
> RCS file: /cvs/src/usr.bin/rcs/xmalloc.c,v
> retrieving revision 1.8
> diff -u -p -r1.8 xmalloc.c
> --- xmalloc.c 26 Mar 2015 15:17:30 -0000      1.8
> +++ xmalloc.c 20 May 2015 08:53:01 -0000
> @@ -76,13 +76,11 @@ xfree(void *ptr)
>  char *
>  xstrdup(const char *str)
>  {
> -     size_t len;
>       char *cp;
>  
> -     len = strlen(str) + 1;
> -     cp = xmalloc(len);
> -     if (strlcpy(cp, str, len) >= len)
> -             errx(1, "xstrdup: string truncated");
> +     if ((cp = strdup(str)) == NULL)
> +             err(1, "xstrdup: copy string failed");
> +
>       return cp;
>  }
>  

Reply via email to