From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1386) id 1F9DE3858D28; Mon, 24 Apr 2023 08:37:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1F9DE3858D28 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Jan Beulich To: bfd-cvs@sourceware.org Subject: [binutils-gdb] x86: work around compiler diagnosing dangling pointer X-Act-Checkin: binutils-gdb X-Git-Author: Jan Beulich X-Git-Refname: refs/heads/master X-Git-Oldrev: d4a174a5cbb794143164897a4e8a08972fd251a1 X-Git-Newrev: 983db9932a302f9e2ae1f1d4fd7c3149560bc269 Message-Id: <20230424083722.1F9DE3858D28@sourceware.org> Date: Mon, 24 Apr 2023 08:37:22 +0000 (GMT) X-BeenThere: binutils-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 24 Apr 2023 08:37:22 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D983db9932a30= 2f9e2ae1f1d4fd7c3149560bc269 commit 983db9932a302f9e2ae1f1d4fd7c3149560bc269 Author: Jan Beulich Date: Mon Apr 24 10:37:12 2023 +0200 x86: work around compiler diagnosing dangling pointer =20 For quite come time print_insn() has been storing the address of a local variable into info->private_data. Since the compiler can't know that the field won't be accessed again after print_insn() returns, it may kind of legitimately diagnose this. And recent enough gcc does as of the introduction of the fetch_error() return paths (replacing setjmp()-based error handling). =20 Utilizing that neither prefix_name() nor i386_dis_printf() actually use info->private_data, zap the pointer in fetch_error(), after having retrieved it for local use. Diff: --- opcodes/i386-dis.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/opcodes/i386-dis.c b/opcodes/i386-dis.c index f021bdaa3e7..fc0515cd2b0 100644 --- a/opcodes/i386-dis.c +++ b/opcodes/i386-dis.c @@ -345,6 +345,12 @@ fetch_error (const instr_info *ins) const struct dis_private *priv =3D ins->info->private_data; const char *name =3D NULL; =20 + /* Our caller has put a pointer to a local variable in info->private_data + and it is going to return right after this function has returned. So= me + compilers diagnose this as a dangling pointer. Zap the pointer here = to + avoid needing to do so on all involved return paths in the caller. */ + ins->info->private_data =3D NULL; + if (ins->codep <=3D priv->the_buffer) return -1;