]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Remove a couple of VLAs
authorTom Tromey <tom@tromey.com>
Tue, 16 Apr 2024 19:12:28 +0000 (13:12 -0600)
committerTom Tromey <tom@tromey.com>
Sun, 21 Apr 2024 18:33:56 +0000 (12:33 -0600)
I found a couple of spots where VLAs are in use but where they can
easily be removed.

In one spot, adding 'const' is enough -- and is already done in
similar code elsewhere in the file.

In another spot, one of two arrays will be used, so making the buffer
large enough for both works.

Approved-By: John Baldwin <jhb@FreeBSD.org>
gdb/aarch64-tdep.c
gdb/arc-linux-tdep.c

index 545ec872fd86a48052cdca3213757d15daad1317..06eda102468a3153f57cf9514dfe8ead8678c9e7 100644 (file)
@@ -5713,7 +5713,7 @@ aarch64_process_record (struct gdbarch *gdbarch, struct regcache *regcache,
                        CORE_ADDR insn_addr)
 {
   uint32_t rec_no = 0;
-  uint8_t insn_size = 4;
+  const uint8_t insn_size = 4;
   uint32_t ret = 0;
   gdb_byte buf[insn_size];
   aarch64_insn_decode_record aarch64_record;
index 54406ac5b9074a790f004ad34cfd1eb4bfbe06ff..30bd40c8027e97e3fec26eed526e434d7ee16e6b 100644 (file)
@@ -174,6 +174,9 @@ arc_linux_is_sigtramp (const frame_info_ptr &this_frame)
     0x22, 0x6f, 0x00, 0x3f     /* swi */
   };
 
+  constexpr size_t max_insn_sz = std::max (sizeof (insns_be_hs),
+                                          sizeof (insns_be_700));
+
   gdb_byte arc_sigtramp_insns[sizeof (insns_be_700)];
   size_t insns_sz;
   if (arc_mach_is_arcv2 (gdbarch))
@@ -200,7 +203,8 @@ arc_linux_is_sigtramp (const frame_info_ptr &this_frame)
        std::swap (arc_sigtramp_insns[i], arc_sigtramp_insns[i+1]);
     }
 
-  gdb_byte buf[insns_sz];
+  gdb_assert (insns_sz <= max_insn_sz);
+  gdb_byte buf[max_insn_sz];
 
   /* Read the memory at the PC.  Since we are stopped, any breakpoint must
      have been removed.  */