[PATCH] use xstrdup and concat more
Alan Modra
amodra@gmail.com
Wed Apr 27 11:59:00 GMT 2016
On Wed, Apr 27, 2016 at 06:20:53AM -0400, Trevor Saunders wrote:
> > +static inline void *
> > +xmemdup0 (const void *in, size_t len)
> > +{
> > + char *out = (char *) xmalloc (len + 1);
> > + out[len] = 0;
> > + return memcpy (out, in, len);
>
> Given we always use this with strings, and null terminating other things
> with 1 zero byte doesn't seem to make a lot of sense should this return
> char *? I can make that change with my patch if you agree.
I chose void * to be like xmemdup, but as you say, the function will
probably only be used to copy strings. Feel free to change the param
and result to char * (and cast memcpy result).
--
Alan Modra
Australia Development Lab, IBM
More information about the Binutils
mailing list