From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from rock.gnat.com (rock.gnat.com [205.232.38.15]) by sourceware.org (Postfix) with ESMTP id 87E69385040F for ; Mon, 8 Feb 2021 15:24:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 87E69385040F Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tromey@adacore.com Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 15CB3116DD5; Mon, 8 Feb 2021 10:24:50 -0500 (EST) X-Virus-Scanned: Debian amavisd-new at gnat.com Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id vGF8HQG9LrsK; Mon, 8 Feb 2021 10:24:50 -0500 (EST) Received: from murgatroyd.Home (97-122-91-54.hlrn.qwest.net [97.122.91.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by rock.gnat.com (Postfix) with ESMTPSA id C7157116684; Mon, 8 Feb 2021 10:24:49 -0500 (EST) From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 1/2] Avoid crash in resolve_dynamic_struct Date: Mon, 8 Feb 2021 08:24:47 -0700 Message-Id: <20210208152448.341199-2-tromey@adacore.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210208152448.341199-1-tromey@adacore.com> References: <20210208152448.341199-1-tromey@adacore.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-11.3 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 08 Feb 2021 15:24:51 -0000 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 * 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