Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* RFA: fix crash-causing bug in copy_type_recursive
@ 2008-11-10 20:08 Tom Tromey
  2008-11-10 20:57 ` Daniel Jacobowitz
  2008-11-10 21:22 ` Pedro Alves
  0 siblings, 2 replies; 5+ messages in thread
From: Tom Tromey @ 2008-11-10 20:08 UTC (permalink / raw)
  To: gdb-patches

On the Python branch I ran into a crash that was caused by
copy_type_recursive not clearing the memory for new fields.  This was
probably introduced when I changed all the type flags back in August,
but I didn't research to see for sure.

The fix is to clear the newly allocated memory.
Every other places that allocates new fields does this.

I do not have a test failing case for trunk.

Built and regtested on x86-64 (compile farm).
Ok?  (I almost checked this in as obvious...)

Tom

2008-11-10  Tom Tromey  <tromey@redhat.com>

	* gdbtypes.c (copy_type_recursive): Clear new fields.

diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index b5a5de0..5b9d0e8 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -2977,6 +2977,7 @@ copy_type_recursive (struct objfile *objfile,
 
       nfields = TYPE_NFIELDS (type);
       TYPE_FIELDS (new_type) = xmalloc (sizeof (struct field) * nfields);
+      memset (TYPE_FIELDS (new_type), 0, sizeof (struct field) * nfields);
       for (i = 0; i < nfields; i++)
 	{
 	  TYPE_FIELD_ARTIFICIAL (new_type, i) = 


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: RFA: fix crash-causing bug in copy_type_recursive
  2008-11-10 20:08 RFA: fix crash-causing bug in copy_type_recursive Tom Tromey
@ 2008-11-10 20:57 ` Daniel Jacobowitz
  2008-11-10 21:22 ` Pedro Alves
  1 sibling, 0 replies; 5+ messages in thread
From: Daniel Jacobowitz @ 2008-11-10 20:57 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches

On Mon, Nov 10, 2008 at 12:40:01PM -0700, Tom Tromey wrote:
> Built and regtested on x86-64 (compile farm).
> Ok?  (I almost checked this in as obvious...)

Go right ahead (or use XZALLOC...).

-- 
Daniel Jacobowitz
CodeSourcery


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: RFA: fix crash-causing bug in copy_type_recursive
  2008-11-10 20:08 RFA: fix crash-causing bug in copy_type_recursive Tom Tromey
  2008-11-10 20:57 ` Daniel Jacobowitz
@ 2008-11-10 21:22 ` Pedro Alves
  2008-11-10 21:26   ` Tom Tromey
  1 sibling, 1 reply; 5+ messages in thread
From: Pedro Alves @ 2008-11-10 21:22 UTC (permalink / raw)
  To: gdb-patches, Tom Tromey

On Monday 10 November 2008 19:40:01, Tom Tromey wrote:
> On the Python branch I ran into a crash that was caused by
> copy_type_recursive not clearing the memory for new fields.  

> Built and regtested on x86-64 (compile farm).
> Ok?  (I almost checked this in as obvious...)
> 

Ok.

> @@ -2977,6 +2977,7 @@ copy_type_recursive (struct objfile *objfile,
>  
>        nfields = TYPE_NFIELDS (type);
>        TYPE_FIELDS (new_type) = xmalloc (sizeof (struct field) * nfields);
> +      memset (TYPE_FIELDS (new_type), 0, sizeof (struct field) * nfields);

Or xzalloc, or xcalloc, or XCALLOC even.

-- 
Pedro Alves


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: RFA: fix crash-causing bug in copy_type_recursive
  2008-11-10 21:22 ` Pedro Alves
@ 2008-11-10 21:26   ` Tom Tromey
  2008-11-10 23:10     ` Pedro Alves
  0 siblings, 1 reply; 5+ messages in thread
From: Tom Tromey @ 2008-11-10 21:26 UTC (permalink / raw)
  To: Pedro Alves; +Cc: gdb-patches

>>>>> "Pedro" == Pedro Alves <pedro@codesourcery.com> writes:

>> +      memset (TYPE_FIELDS (new_type), 0, sizeof (struct field) * nfields);

Pedro> Or xzalloc, or xcalloc, or XCALLOC even.

I would have done this, but all other initializations of this field
use xmalloc + memset.  So, I opted for consistency.

Tom


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: RFA: fix crash-causing bug in copy_type_recursive
  2008-11-10 21:26   ` Tom Tromey
@ 2008-11-10 23:10     ` Pedro Alves
  0 siblings, 0 replies; 5+ messages in thread
From: Pedro Alves @ 2008-11-10 23:10 UTC (permalink / raw)
  To: gdb-patches, Tom Tromey

On Monday 10 November 2008 20:52:44, Tom Tromey wrote:
> >>>>> "Pedro" == Pedro Alves <pedro@codesourcery.com> writes:
> 
> >> +      memset (TYPE_FIELDS (new_type), 0, sizeof (struct field) * nfields);
> 
> Pedro> Or xzalloc, or xcalloc, or XCALLOC even.
> 
> I would have done this, but all other initializations of this field
> use xmalloc + memset.  So, I opted for consistency.
> 

Fair enough.  That's an argument I tend to use myself, as you know.

-- 
Pedro Alves


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2008-11-10 21:26 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-11-10 20:08 RFA: fix crash-causing bug in copy_type_recursive Tom Tromey
2008-11-10 20:57 ` Daniel Jacobowitz
2008-11-10 21:22 ` Pedro Alves
2008-11-10 21:26   ` Tom Tromey
2008-11-10 23:10     ` Pedro Alves

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox