RFC: fix latent bug in syms_from_objfile_1
Jan Kratochvil
jan.kratochvil@redhat.com
Thu Mar 21 14:41:00 GMT 2013
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
More information about the Gdb-patches
mailing list