public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [PATCH] Remove a couple of VLAs
Date: Wed, 17 Apr 2024 17:01:12 -0600	[thread overview]
Message-ID: <20240417230112.1791762-1-tom@tromey.com> (raw)

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.
---
 gdb/aarch64-tdep.c   | 2 +-
 gdb/arc-linux-tdep.c | 6 +++++-
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/gdb/aarch64-tdep.c b/gdb/aarch64-tdep.c
index 545ec872fd8..06eda102468 100644
--- a/gdb/aarch64-tdep.c
+++ b/gdb/aarch64-tdep.c
@@ -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;
diff --git a/gdb/arc-linux-tdep.c b/gdb/arc-linux-tdep.c
index 54406ac5b90..30bd40c8027 100644
--- a/gdb/arc-linux-tdep.c
+++ b/gdb/arc-linux-tdep.c
@@ -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.  */
-- 
2.44.0


             reply	other threads:[~2024-04-17 23:01 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-17 23:01 Tom Tromey [this message]
2024-04-20 20:27 ` John Baldwin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240417230112.1791762-1-tom@tromey.com \
    --to=tom@tromey.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).