aboutsummaryrefslogtreecommitdiff
path: root/gdb/dwarf2read.c
diff options
context:
space:
mode:
authorJan Kratochvil <jan.kratochvil@redhat.com>2010-03-31 18:13:38 +0000
committerJan Kratochvil <jan.kratochvil@redhat.com>2010-03-31 18:13:38 +0000
commit8072405bd6f570b75a030fbd81f25ac79260b066 (patch)
treee571e5fc3be62ede08bc679a272aa75fc2499113 /gdb/dwarf2read.c
parent8bf6485c1cee41f31564e1097199ff67a3615ebe (diff)
downloadgdb-8072405bd6f570b75a030fbd81f25ac79260b066.zip
gdb-8072405bd6f570b75a030fbd81f25ac79260b066.tar.gz
gdb-8072405bd6f570b75a030fbd81f25ac79260b066.tar.bz2
gdb/
Fix crash on reading wrong function declaration DWARF. * dwarf2read.c (read_subroutine_type): New variable void_type. Pre-fill all TYPE_FIELD_TYPEs. Move nparams and iparams initialization more close to their use. gdb/testsuite/ * gdb.dwarf2/dw2-bad-parameter-type.exp, gdb.dwarf2/dw2-bad-parameter-type.S: New.
Diffstat (limited to 'gdb/dwarf2read.c')
-rw-r--r--gdb/dwarf2read.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index ed25124..d16cea4 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -5938,13 +5938,14 @@ read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu)
if (die->child != NULL)
{
+ struct type *void_type = objfile_type (cu->objfile)->builtin_void;
struct die_info *child_die;
- int nparams = 0;
- int iparams = 0;
+ int nparams, iparams;
/* Count the number of parameters.
FIXME: GDB currently ignores vararg functions, but knows about
vararg member functions. */
+ nparams = 0;
child_die = die->child;
while (child_die && child_die->tag)
{
@@ -5960,6 +5961,12 @@ read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu)
TYPE_FIELDS (ftype) = (struct field *)
TYPE_ZALLOC (ftype, nparams * sizeof (struct field));
+ /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it
+ even if we error out during the parameters reading below. */
+ for (iparams = 0; iparams < nparams; iparams++)
+ TYPE_FIELD_TYPE (ftype, iparams) = void_type;
+
+ iparams = 0;
child_die = die->child;
while (child_die && child_die->tag)
{