This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: [PATCH] use xstrdup and concat more
- From: Alan Modra <amodra at gmail dot com>
- To: Trevor Saunders <tbsaunde at tbsaunde dot org>
- Cc: tbsaunde+binutils at tbsaunde dot org, binutils at sourceware dot org
- Date: Wed, 27 Apr 2016 21:28:53 +0930
- Subject: Re: [PATCH] use xstrdup and concat more
- Authentication-results: sourceware.org; auth=none
- References: <1461483896-3190-1-git-send-email-tbsaunde+binutils at tbsaunde dot org> <20160425130136 dot GH27353 at bubble dot grove dot modra dot org> <20160425135550 dot GE25520 at tsaunders-iceball dot corp dot tor1 dot mozilla dot com> <20160425145629 dot GJ27353 at bubble dot grove dot modra dot org> <20160426235843 dot GC9731 at ball> <20160427061925 dot GB20333 at bubble dot grove dot modra dot org> <20160427101949 dot GA6733 at tsaunders-iceball dot corp dot tor1 dot mozilla dot com>
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