This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [RFA] ada-valprint.c (ada_val_print_array): Assert elttype not null.
- From: Joel Brobecker <brobecker at adacore dot com>
- To: Michael Snyder <msnyder at vmware dot com>
- Cc: "gdb-patches at sourceware dot org" <gdb-patches at sourceware dot org>
- Date: Mon, 7 Mar 2011 13:00:44 +0400
- Subject: Re: [RFA] ada-valprint.c (ada_val_print_array): Assert elttype not null.
- References: <4D7167E7.8010707@vmware.com>
> If we pass null to printstr, it will dereference it.
> 2011-03-04 Michael Snyder <msnyder@vmware.com>
>
> * ada-valprint.c (ada_val_print_array): Assert elttype not null.
As a matter of fact, we wouldn't dereference it, because we would
also pass a null len. But looking deeper, we shouldn't have a NULL
elttype at all in this branch. Attached is what I checked in.
--
Joel
commit 7321f71ee137f68df0297d1e5c020328cd38c79a
Author: Joel Brobecker <brobecker@adacore.com>
Date: Mon Mar 7 12:17:58 2011 +0400
simplify ada-valprint.c:ada_val_print_array
Two things:
- Move the declaration of a couple of variables inside the block
where they are actually used;
- Remove some code that checks against NULL/zero, because the
condition should always be false. Add some gdb_asserts to
make sure we never fail those assumptions.
gdb/ChangeLog:
* ada-valprint.c (ada_val_print_array): Move the declaration of
"byte_order" and "elttype" inside the block where these variables
are actually used. Remove some special handling for the case
where "elttype" and "eltlen" are null. Replace by a comment
and a couple of assertion checks.
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 4887026..965917c 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,12 @@
+2011-03-07 Joel Brobecker <brobecker@adacore.com>
+ Michael Snyder <msnyder@vmware.com>
+
+ * ada-valprint.c (ada_val_print_array): Move the declaration of
+ "byte_order" and "elttype" inside the block where these variables
+ are actually used. Remove some special handling for the case
+ where "elttype" and "eltlen" are null. Replace by a comment
+ and a couple of assertion checks.
+
2011-03-05 Michael Snyder <msnyder@vmware.com>
* source.c (add_path): Replace semicolon at end of block.
diff --git a/gdb/ada-valprint.c b/gdb/ada-valprint.c
index 9381ecc..09266ce 100644
--- a/gdb/ada-valprint.c
+++ b/gdb/ada-valprint.c
@@ -605,25 +605,25 @@ ada_val_print_array (struct type *type, const gdb_byte *valaddr,
const struct value *val,
const struct value_print_options *options)
{
- enum bfd_endian byte_order = gdbarch_byte_order (get_type_arch (type));
- struct type *elttype = TYPE_TARGET_TYPE (type);
int result = 0;
/* For an array of chars, print with string syntax. */
if (ada_is_string_type (type)
&& (options->format == 0 || options->format == 's'))
{
+ enum bfd_endian byte_order = gdbarch_byte_order (get_type_arch (type));
+ struct type *elttype = TYPE_TARGET_TYPE (type);
unsigned int eltlen;
unsigned int len;
- if (elttype == NULL)
- eltlen = 0;
- else
- eltlen = TYPE_LENGTH (elttype);
- if (eltlen == 0)
- len = 0;
- else
- len = TYPE_LENGTH (type) / eltlen;
+ /* We know that ELTTYPE cannot possibly be null, because we found
+ that TYPE is a string-like type. Similarly, the size of ELTTYPE
+ should also be non-null, since it's a character-like type. */
+ gdb_assert (elttype != NULL);
+ gdb_assert (TYPE_LENGTH (elttype) != 0);
+
+ eltlen = TYPE_LENGTH (elttype);
+ len = TYPE_LENGTH (type) / eltlen;
if (options->prettyprint_arrays)
print_spaces_filtered (2 + 2 * recurse, stream);