summaryrefslogtreecommitdiff
path: root/gdb/ada-valprint.c
diff options
context:
space:
mode:
authorJoel Brobecker <brobecker@gnat.com>2011-03-07 08:57:08 +0000
committerJoel Brobecker <brobecker@gnat.com>2011-03-07 08:57:08 +0000
commit197423bc2e1280911452b2066ed7acf35e6a0c71 (patch)
treea01104a4fef2d95b9853fd1881c5e500ceb2dffd /gdb/ada-valprint.c
parent34ea7968ce196d8b967e0b6f5ac75f043bb5d3db (diff)
downloadgdb-197423bc2e1280911452b2066ed7acf35e6a0c71.tar.gz
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.
Diffstat (limited to 'gdb/ada-valprint.c')
-rw-r--r--gdb/ada-valprint.c20
1 files changed, 10 insertions, 10 deletions
diff --git a/gdb/ada-valprint.c b/gdb/ada-valprint.c
index 9381ecca5cd..09266ceb6be 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);