[13/13] gdb: remove a use of alloca from symfile.c

Message ID 1538ddf7e258f98821898f15426f0e88c919e372.1677533215.git.aburgess@redhat.com
State New
Headers
Series Remove a bunch of alloca uses |

Commit Message

Andrew Burgess Feb. 27, 2023, 9:29 p.m. UTC
  Remove a use of alloca from symfile.c and replace it with
gdb::byte_vector.

There is another use of alloca in this file, but this is for a type
other than gdb_byte, so will need something other than
gdb::byte_vector.

There should be no user visible changes after this commit.
---
 gdb/symfile.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)
  

Patch

diff --git a/gdb/symfile.c b/gdb/symfile.c
index 373f5592107..1a9f811f0ba 100644
--- a/gdb/symfile.c
+++ b/gdb/symfile.c
@@ -3429,13 +3429,12 @@  static void
 read_target_long_array (CORE_ADDR memaddr, unsigned int *myaddr,
 			int len, int size, enum bfd_endian byte_order)
 {
-  /* FIXME (alloca): Not safe if array is very large.  */
-  gdb_byte *buf = (gdb_byte *) alloca (len * size);
-  int i;
+  gdb::byte_vector buf (len * size);
 
-  read_memory (memaddr, buf, len * size);
-  for (i = 0; i < len; i++)
-    myaddr[i] = extract_unsigned_integer (size * i + buf, size, byte_order);
+  read_memory (memaddr, buf.data (), len * size);
+  for (int i = 0; i < len; i++)
+    myaddr[i] = extract_unsigned_integer (size * i + buf.data (), size,
+					  byte_order);
 }
 
 /* Find and grab a copy of the target _ovly_table