This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB 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: RFC: fix latent bug in syms_from_objfile_1


On Wed, 20 Mar 2013 20:50:10 +0100, Tom Tromey wrote:
> --- a/gdb/symfile.c
> +++ b/gdb/symfile.c
[...]
> @@ -205,11 +207,14 @@ alloc_section_addr_info (size_t num_sections)
>    struct section_addr_info *sap;
>    size_t size;
>  
> +  /* Make sure the size calculation turns out ok.  */
> +  if (num_sections == 0)
> +    ++num_sections;

I always thought such sizeof calculation works even with # of elements == 0.
Why not?


> +
>    size = (sizeof (struct section_addr_info)
>  	  +  sizeof (struct other_sections) * (num_sections - 1));
>    sap = (struct section_addr_info *) xmalloc (size);
>    memset (sap, 0, size);
> -  sap->num_sections = num_sections;
>  
>    return sap;
>  }


I am OK with the patch, thanks for the cleanup waiting for so many years.


Jan


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