From: Tom Tromey <tromey@adacore.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tromey@adacore.com>
Subject: [PATCH 1/2] Avoid crash in resolve_dynamic_struct
Date: Mon, 8 Feb 2021 08:24:47 -0700 [thread overview]
Message-ID: <20210208152448.341199-2-tromey@adacore.com> (raw)
In-Reply-To: <20210208152448.341199-1-tromey@adacore.com>
resolve_dynamic_struct says:
gdb_assert (type->num_fields () > 0);
However, a certain Ada program has a structure with no fields but with
a dynamic size, causing this assertion to fire.
It is difficult to be certain, but we think this is a compiler bug.
However, in the meantime this assertion does not seem to be checking
any kind of internal consistency; so this patch removes it.
gdb/ChangeLog
2021-02-08 Tom Tromey <tromey@adacore.com>
* gdbtypes.c (resolve_dynamic_struct): Handle structure with no
fields.
---
gdb/ChangeLog | 5 +++++
gdb/gdbtypes.c | 8 ++++----
2 files changed, 9 insertions(+), 4 deletions(-)
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index c736dff2ca8..1b2d4836959 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -2545,7 +2545,6 @@ resolve_dynamic_struct (struct type *type,
unsigned resolved_type_bit_length = 0;
gdb_assert (type->code () == TYPE_CODE_STRUCT);
- gdb_assert (type->num_fields () > 0);
resolved_type = copy_type (type);
@@ -2564,9 +2563,10 @@ resolve_dynamic_struct (struct type *type,
((struct field *)
TYPE_ALLOC (resolved_type,
resolved_type->num_fields () * sizeof (struct field)));
- memcpy (resolved_type->fields (),
- type->fields (),
- resolved_type->num_fields () * sizeof (struct field));
+ if (type->num_fields () > 0)
+ memcpy (resolved_type->fields (),
+ type->fields (),
+ resolved_type->num_fields () * sizeof (struct field));
}
for (i = 0; i < resolved_type->num_fields (); ++i)
--
2.26.2
next prev parent reply other threads:[~2021-02-08 15:24 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-08 15:24 [PATCH 0/2] Fix two crashes with Ada "bt" Tom Tromey
2021-02-08 15:24 ` Tom Tromey [this message]
2021-02-09 9:02 ` [PATCH 1/2] Avoid crash in resolve_dynamic_struct Andrew Burgess
2021-02-08 15:24 ` [PATCH 2/2] Avoid crash from coerce_unspec_val_to_type Tom Tromey
2021-02-09 15:56 ` Andrew Burgess
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210208152448.341199-2-tromey@adacore.com \
--to=tromey@adacore.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).