This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: RFC: fix latent bug in syms_from_objfile_1
- From: Jan Kratochvil <jan dot kratochvil at redhat dot com>
- To: Tom Tromey <tromey at redhat dot com>
- Cc: gdb-patches at sourceware dot org
- Date: Thu, 21 Mar 2013 15:19:54 +0100
- Subject: Re: RFC: fix latent bug in syms_from_objfile_1
- References: <87ip4m7wxy dot fsf at fleche dot redhat dot com> <20130320184034 dot GA708 at host2 dot jankratochvil dot net> <87ip4l7swd dot fsf at fleche dot redhat dot com>
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