]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Avoid use of alloca in read_array_type
authorTom Tromey <tromey@adacore.com>
Wed, 11 Mar 2026 13:50:25 +0000 (07:50 -0600)
committerTom Tromey <tromey@adacore.com>
Wed, 11 Mar 2026 17:46:43 +0000 (11:46 -0600)
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 <simon.marchi@efficios.com>
gdb/dwarf2/read.c

index f61b09f3138c2b17b4b17abad343228dbcf5735c..25ea7644ed08e59f11e9e521cac8ddeafcda8504 100644 (file)
@@ -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)