public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Jan Beulich <jbeulich@suse.com>
To: Binutils <binutils@sourceware.org>
Cc: "H.J. Lu" <hjl.tools@gmail.com>
Subject: [PATCH 2/3] x86: limit data passed to prefix_name()
Date: Mon, 24 Apr 2023 09:35:05 +0200	[thread overview]
Message-ID: <c26e2fcd-62aa-98f3-1b62-0c53ce7d16a5@suse.com> (raw)
In-Reply-To: <61597ebf-cc5e-2029-6520-31f7adfeea68@suse.com>

Make apparent that neither what "ins" points to nor, in particular, that
"ins->info->private_data" is actually used in the function.

--- a/opcodes/i386-dis.c
+++ b/opcodes/i386-dis.c
@@ -117,7 +117,6 @@ static bool PREFETCHI_Fixup (instr_info
 static void ATTRIBUTE_PRINTF_3 i386_dis_printf (const instr_info *,
 						enum disassembler_style,
 						const char *, ...);
-static const char *prefix_name (const instr_info *, int, int);
 
 /* This character is used to encode style information within the output
    buffers.  See oappend_insert_style for more details.  */
@@ -141,6 +140,8 @@ enum address_mode
   mode_64bit
 };
 
+static const char *prefix_name (enum address_mode, int, int);
+
 enum x86_64_isa
 {
   amd64 = 1,
@@ -355,7 +356,8 @@ fetch_error (const instr_info *ins)
     return -1;
 
   if (ins->prefixes || ins->fwait_prefix >= 0 || (ins->rex & REX_OPCODE))
-    name = prefix_name (ins, priv->the_buffer[0], priv->orig_sizeflag);
+    name = prefix_name (ins->address_mode, priv->the_buffer[0],
+			priv->orig_sizeflag);
   if (name != NULL)
     i386_dis_printf (ins, dis_style_mnemonic, "%s", name);
   else
@@ -8928,7 +8930,7 @@ ckprefix (instr_info *ins)
    prefix byte.  */
 
 static const char *
-prefix_name (const instr_info *ins, int pref, int sizeflag)
+prefix_name (enum address_mode mode, int pref, int sizeflag)
 {
   static const char *rexes [16] =
     {
@@ -8991,7 +8993,7 @@ prefix_name (const instr_info *ins, int
     case 0x66:
       return (sizeflag & DFLAG) ? "data16" : "data32";
     case 0x67:
-      if (ins->address_mode == mode_64bit)
+      if (mode == mode_64bit)
 	return (sizeflag & AFLAG) ? "addr32" : "addr64";
       else
 	return (sizeflag & AFLAG) ? "addr16" : "addr32";
@@ -9767,7 +9769,8 @@ print_insn (bfd_vma pc, disassemble_info
 	   i++)
 	i386_dis_printf (&ins, dis_style_mnemonic, "%s%s",
 			 (i == 0 ? "" : " "),
-			 prefix_name (&ins, ins.all_prefixes[i], sizeflag));
+			 prefix_name (ins.address_mode, ins.all_prefixes[i],
+				      sizeflag));
       return i;
 
     case ckp_fetch_error:
@@ -9788,7 +9791,8 @@ print_insn (bfd_vma pc, disassemble_info
       for (i = 0; i < ins.fwait_prefix && ins.all_prefixes[i];
 	   i++)
 	i386_dis_printf (&ins, dis_style_mnemonic, "%s ",
-			 prefix_name (&ins, ins.all_prefixes[i], sizeflag));
+			 prefix_name (ins.address_mode, ins.all_prefixes[i],
+				      sizeflag));
       i386_dis_printf (&ins, dis_style_mnemonic, "fwait");
       return i + 1;
     }
@@ -10025,8 +10029,9 @@ print_insn (bfd_vma pc, disassemble_info
   for (i = 0; i < (int) ARRAY_SIZE (ins.all_prefixes); i++)
     if (ins.all_prefixes[i])
       {
-	const char *name;
-	name = prefix_name (&ins, ins.all_prefixes[i], orig_sizeflag);
+	const char *name = prefix_name (ins.address_mode, ins.all_prefixes[i],
+					orig_sizeflag);
+
 	if (name == NULL)
 	  abort ();
 	prefix_length += strlen (name) + 1;


  parent reply	other threads:[~2023-04-24  7:35 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-24  7:33 [PATCH 0/3] x86: further disassembler tweaks Jan Beulich
2023-04-24  7:34 ` [PATCH 1/3] x86: work around compiler diagnosing dangling pointer Jan Beulich
2023-04-24 10:24   ` Alan Modra
2023-04-24 10:35     ` Jan Beulich
2023-04-24  7:35 ` Jan Beulich [this message]
2023-04-24  7:35 ` [PATCH 3/3] x86: limit data passed to i386_dis_printf() Jan Beulich

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=c26e2fcd-62aa-98f3-1b62-0c53ce7d16a5@suse.com \
    --to=jbeulich@suse.com \
    --cc=binutils@sourceware.org \
    --cc=hjl.tools@gmail.com \
    /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).