[binutils-gdb] Avoid use of alloca in read_array_type
Tom Tromey via Gdb-cvs <[email protected]>
| Newsgroups | gmane.comp.gdb.cvs |
|---|---|
| Message-ID | <[email protected]> |
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=00636a10192ef4dfa2c9cdd73818e5ebfa144c69 commit 00636a10192ef4dfa2c9cdd73818e5ebfa144c69 Author: Tom Tromey <[email protected]> Date: Wed Mar 11 07:50:25 2026 -0600 Avoid use of alloca in read_array_type I think alloca should generally be avoided, and the use in dwarf2/read.c:read_array_type is easily replaced with a local storage object. Approved-By: Simon Marchi <[email protected]> Diff: --- gdb/dwarf2/read.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index f61b09f3138..25ea7644ed0 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -11485,9 +11485,14 @@ read_array_type (struct die_info *die, struct dwarf2_cu *cu) struct type *type; struct type *element_type, *range_type, *index_type; const char *name; - struct dynamic_prop *byte_stride_prop = NULL; unsigned int bit_stride = 0; + /* If the stride is seen and used, byte_stride_prop will be + non-NULL. In this case stride_storage will be used to store the + data locally. */ + dynamic_prop *byte_stride_prop = nullptr; + dynamic_prop stride_storage; + element_type = die_type (die, cu); /* The die_type call above may have already set the type for this DIE. */ @@ -11501,8 +11506,7 @@ read_array_type (struct die_info *die, struct dwarf2_cu *cu) int stride_ok; struct type *prop_type = cu->addr_sized_int_type (false); - byte_stride_prop - = (struct dynamic_prop *) alloca (sizeof (struct dynamic_prop)); + byte_stride_prop = &stride_storage; stride_ok = attr_to_dynamic_prop (attr, die, cu, byte_stride_prop, prop_type); if (!stride_ok)