Check index in type::field

This changes gdb to check the index that is passed to type::field.
This caught one bug in the Ada code when running the test suite
(actually I found the bug first, then realized that the check would
have helped), so this patch fixes that as well.

Regression tested on x86-64 Fedora 34.
This commit is contained in:
Tom Tromey
2021-10-18 12:32:18 -06:00
parent 775d36a916
commit 5a8edb756a
3 changed files with 3 additions and 2 deletions

View File

@@ -5842,11 +5842,11 @@ append_flags_type_field (struct type *type, int start_bitpos, int nr_bits,
gdb_assert (nr_bits >= 1 && (start_bitpos + nr_bits) <= type_bitsize);
gdb_assert (name != NULL);
type->set_num_fields (type->num_fields () + 1);
type->field (field_nr).set_name (xstrdup (name));
type->field (field_nr).set_type (field_type);
type->field (field_nr).set_loc_bitpos (start_bitpos);
TYPE_FIELD_BITSIZE (type, field_nr) = nr_bits;
type->set_num_fields (type->num_fields () + 1);
}
/* Special version of append_flags_type_field to add a flag field.