From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1726) id 4AA473857C45; Sat, 25 Feb 2023 11:13:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4AA473857C45 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1677323592; bh=wMu7kdNwhoCNAXwAbZdfwt1XNbIsTLmAT8ZuPSR42gY=; h=From:To:Subject:Date:From; b=OMIv4aMWJZTHyWIl3vwSl0dZJZAfVEcjUOsp4jAdIx7btNzVoyKt5TakyuaBRc1t9 F9iWCKnXQEpk57Qp9r6M/1i2UBdMjk9rmvunjutMOB+Ag595OXxLx8KlJc2AvRM4w3 GJHnFyX3e6RZlUowH3KTkhq7GJud0YOF32CtjcqM= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Andrew Burgess To: gdb-cvs@sourceware.org Subject: [binutils-gdb] gdb/amd64: replace xmalloc/alloca with gdb::byte_vector X-Act-Checkin: binutils-gdb X-Git-Author: Andrew Burgess X-Git-Refname: refs/heads/master X-Git-Oldrev: 82341e9798202fa94b801b1428a8bf68dc80149a X-Git-Newrev: 83750264d7bab2627e59b6682710bbfdc588bbb4 Message-Id: <20230225111312.4AA473857C45@sourceware.org> Date: Sat, 25 Feb 2023 11:13:12 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D83750264d7ba= b2627e59b6682710bbfdc588bbb4 commit 83750264d7bab2627e59b6682710bbfdc588bbb4 Author: Andrew Burgess Date: Thu Feb 23 10:34:39 2023 +0000 gdb/amd64: replace xmalloc/alloca with gdb::byte_vector =20 Replace a couple of uses of xmalloc and alloc with a gdb::byte_vector local variable instead. =20 There should be no user visible changes after this commit. =20 Reviewed-By: Tom Tromey Diff: --- 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, CO= RE_ADDR addr, int (*pred) (const struct amd64_insn *)) { struct amd64_insn details; - gdb_byte *buf; - int len, classification; =20 - len =3D gdbarch_max_insn_length (gdbarch); - buf =3D (gdb_byte *) alloca (len); + gdb::byte_vector buf (gdbarch_max_insn_length (gdbarch)); =20 - 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); =20 - classification =3D pred (&details); + int classification =3D pred (&details); =20 return classification; } @@ -1836,21 +1833,21 @@ amd64_relocate_instruction (struct gdbarch *gdbarch, int len =3D gdbarch_max_insn_length (gdbarch); /* Extra space for sentinels. */ int fixup_sentinel_space =3D len; - gdb_byte *buf =3D (gdb_byte *) xmalloc (len + fixup_sentinel_space); + gdb::byte_vector buf (len + fixup_sentinel_space); struct amd64_insn insn_details; int offset =3D 0; LONGEST rel32, newrel; gdb_byte *insn; int insn_length; =20 - read_memory (oldloc, buf, len); + read_memory (oldloc, buf.data (), len); =20 /* 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); =20 - insn =3D buf; + insn =3D buf.data (); amd64_get_insn_details (insn, &insn_details); =20 insn_length =3D gdb_buffered_insn_length (gdbarch, insn, len, oldloc); @@ -1945,7 +1942,7 @@ amd64_relocate_instruction (struct gdbarch *gdbarch, } =20 /* Write the adjusted instruction into its displaced location. */ - append_insns (to, insn_length, buf); + append_insns (to, insn_length, buf.data ()); }