public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Andrew Burgess <aburgess@redhat.com>
To: gdb-patches@sourceware.org
Cc: Andrew Burgess <aburgess@redhat.com>
Subject: [PATCH] gdb/amd64: replace xmalloc/alloca with gdb::byte_vector
Date: Thu, 23 Feb 2023 15:47:59 +0000	[thread overview]
Message-ID: <810b37f52627188ebfba31684dac71f910a960d7.1677167272.git.aburgess@redhat.com> (raw)

Replace a couple of uses of xmalloc and alloc with a gdb::byte_vector
local variable instead.

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

diff --git a/gdb/amd64-tdep.c b/gdb/amd64-tdep.c
index 0ae09dc7bfb..c4603e8252d 100644
--- a/gdb/amd64-tdep.c
+++ b/gdb/amd64-tdep.c
@@ -1648,16 +1648,13 @@ amd64_classify_insn_at (struct gdbarch *gdbarch, CORE_ADDR addr,
 			int (*pred) (const struct amd64_insn *))
 {
   struct amd64_insn details;
-  gdb_byte *buf;
-  int len, classification;
 
-  len = gdbarch_max_insn_length (gdbarch);
-  buf = (gdb_byte *) alloca (len);
+  gdb::byte_vector buf (gdbarch_max_insn_length (gdbarch));
 
-  read_code (addr, buf, len);
-  amd64_get_insn_details (buf, &details);
+  read_code (addr, buf.data (), buf.size ());
+  amd64_get_insn_details (buf.data (), &details);
 
-  classification = pred (&details);
+  int classification = pred (&details);
 
   return classification;
 }
@@ -1836,21 +1833,21 @@ amd64_relocate_instruction (struct gdbarch *gdbarch,
   int len = gdbarch_max_insn_length (gdbarch);
   /* Extra space for sentinels.  */
   int fixup_sentinel_space = len;
-  gdb_byte *buf = (gdb_byte *) xmalloc (len + fixup_sentinel_space);
+  gdb::byte_vector buf (len + fixup_sentinel_space);
   struct amd64_insn insn_details;
   int offset = 0;
   LONGEST rel32, newrel;
   gdb_byte *insn;
   int insn_length;
 
-  read_memory (oldloc, buf, len);
+  read_memory (oldloc, buf.data (), len);
 
   /* Set up the sentinel space so we don't have to worry about running
      off the end of the buffer.  An excessive number of leading prefixes
      could otherwise cause this.  */
-  memset (buf + len, 0, fixup_sentinel_space);
+  memset (buf.data () + len, 0, fixup_sentinel_space);
 
-  insn = buf;
+  insn = buf.data ();
   amd64_get_insn_details (insn, &insn_details);
 
   insn_length = gdb_buffered_insn_length (gdbarch, insn, len, oldloc);
@@ -1945,7 +1942,7 @@ amd64_relocate_instruction (struct gdbarch *gdbarch,
     }
 
   /* Write the adjusted instruction into its displaced location.  */
-  append_insns (to, insn_length, buf);
+  append_insns (to, insn_length, buf.data ());
 }
 
 \f

base-commit: 5e39600a691e3ba76acf6ab94edb24844c2e82b7
-- 
2.25.4


             reply	other threads:[~2023-02-23 15:48 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-23 15:47 Andrew Burgess [this message]
2023-02-24 19:12 ` Tom Tromey

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=810b37f52627188ebfba31684dac71f910a960d7.1677167272.git.aburgess@redhat.com \
    --to=aburgess@redhat.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).