This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] use xstrdup and concat more


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]