[04/13] gdb: remove use of alloca from corefile.c

Message ID ea3dd33a19f563f0d0bfce0c5399082d2a1bb7db.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 uses of alloca from corefile.c and replace with
gdb::byte_vector.

There should be no user visible changes after this commit.
---
 gdb/corefile.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)
  

Patch

diff --git a/gdb/corefile.c b/gdb/corefile.c
index 5cb559000b8..c76b812f717 100644
--- a/gdb/corefile.c
+++ b/gdb/corefile.c
@@ -334,10 +334,10 @@  read_code_unsigned_integer (CORE_ADDR memaddr, int len,
 CORE_ADDR
 read_memory_typed_address (CORE_ADDR addr, struct type *type)
 {
-  gdb_byte *buf = (gdb_byte *) alloca (type->length ());
+  gdb::byte_vector buf (type->length ());
 
-  read_memory (addr, buf, type->length ());
-  return extract_typed_address (buf, type);
+  read_memory (addr, buf.data (), type->length ());
+  return extract_typed_address (buf.data (), type);
 }
 
 /* See gdbcore.h.  */
@@ -370,10 +370,10 @@  write_memory_unsigned_integer (CORE_ADDR addr, int len,
 			       enum bfd_endian byte_order,
 			       ULONGEST value)
 {
-  gdb_byte *buf = (gdb_byte *) alloca (len);
+  gdb::byte_vector buf (len);
 
-  store_unsigned_integer (buf, len, byte_order, value);
-  write_memory (addr, buf, len);
+  store_unsigned_integer (buf.data (), len, byte_order, value);
+  write_memory (addr, buf.data (), len);
 }
 
 /* Store VALUE at ADDR in the inferior as a LEN-byte signed
@@ -383,10 +383,10 @@  write_memory_signed_integer (CORE_ADDR addr, int len,
 			     enum bfd_endian byte_order,
 			     LONGEST value)
 {
-  gdb_byte *buf = (gdb_byte *) alloca (len);
+  gdb::byte_vector buf (len);
 
-  store_signed_integer (buf, len, byte_order, value);
-  write_memory (addr, buf, len);
+  store_signed_integer (buf.data (), len, byte_order, value);
+  write_memory (addr, buf.data (), len);
 }
 
 /* The current default bfd target.  Points to storage allocated for