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 Mon, Apr 25, 2016 at 10:31:36PM +0930, Alan Modra wrote:
> On Sun, Apr 24, 2016 at 03:44:56AM -0400, tbsaunde+binutils@tbsaunde.org wrote:
> > --- a/gas/config/obj-elf.c
> > +++ b/gas/config/obj-elf.c
> > @@ -949,9 +949,7 @@ obj_elf_section_name (void)
> >  	  return NULL;
> >  	}
> >  
> > -      name = (char *) xmalloc (end - input_line_pointer + 1);
> > -      memcpy (name, input_line_pointer, end - input_line_pointer);
> > -      name[end - input_line_pointer] = '\0';
> > +      name = xstrndup (input_line_pointer, end - input_line_pointer);
> >  
> >        while (flag_sectname_subst)
> >          {
> 
> Is this a good idea, here, and in other places where the original uses
> memcpy and strlen was not called to find the string length?  I'm
> thinking that xstrndup will be needlessly calling strlen.

I guess that's true, I'm not sure if that really matters though?

> Hmm, maybe use xmemdup?  Mind you, the xmemdup implementation isn't
> ideal due to zeroing with xcalloc, but that could be fixed.

 We'd still have to be careful to null terminate ourselves, but I guess
 that would work.  Changing xmemdup scares me a little, but I can't
 think of a way it could be incorrect to use xmalloc there.

 Trev

> 
> -- 
> 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]